Posted to tcl by mjanssen at Wed Jul 04 13:39:09 GMT 2007view pretty

proc login {s host port url} {
    upvar state State
    global env
    fconfigure $s -blocking 1 -buffering line -translation crlf
    sspi::create neg $env(username) $env(userdomain)

    set response [neg token]

    puts $s "GET $url HTTP/1.1\nHost: $host\nProxy-Authorization: Negotiate [base64::encode -wrapchar {} $response]\n"

    set response {}
    while {[set line [gets $s]] ne "" } {
        append response $line\r\n
        # break if headers done
        if {$line == ""} {
            break
        }
    }
    set length {}

    regexp {Content-Length: ([0-9]*)} $response -> length
    regexp {^HTTP/.\.. ([0-9]+)} $response -> status
    puts $status

    if {$length eq {} } {
        set body [read $s]
    } else {
        if {$length != 0 } {
            set body [read $s [expr $length-1] ]
        } else {
            set body {}
        }
    }
    regexp {Proxy-Authenticate: Negotiate (.*)\r\n} $response -> challenge
    puts $challenge
    set challenge [base64::decode $challenge]
    neg next $challenge
    set response [neg token]
    set head [catch {set State(-headers)}]
    set State(-headers) [concat [list Proxy-Authorization [list Negotiate [base64::encode -wrapchar {} $response]]] $head]
    rename neg {}
}

http::config -proxyhost nl-proxy -proxyport 3128 -proxydialog login