Version 7 of autoproxy

Updated 2003-01-21 10:35:30

Supporting proxies with the http package is tedious and error prone and has to be done for each application in turn. I've done a few of these and finally decided this can be done by an external package.

Here is the first draft. I'll add in the handling for proxy authentication soon.

To use this:

  package require autoproxy
  autoproxy::init
  autoproxy::configure -basic -user luser -pass sEkRet

I've incorporated Pat Thoyts' code in a project and it works like a charm. The only small issue being that ProxyOverride apparently does not always exist (according to one problem report I received) -jcw

11dec02 jcw - Another problem is that ProxyEnable may exist but not be a valid boolean.


Automagic proxy authorization header by Anders Ramdahl

The filter is easily changed to automagically add a proxy authorization header when needed. Remember to set autoproxy::user and autoproxy::password before the first http::geturl call.

 proc autoproxy::filter {host} {
     variable user
     variable password
     variable proxy
     variable no_proxy

     if {$proxy(host) == {}} {
         return {}
     }

     foreach domain $no_proxy {
         if {[string match $domain $host]} {
             return {}
         }
     }

     # add proxy authorization header
     upvar state _state
     array set h $_state(-headers)
     set h(Proxy-Authorization) [concat Base [base64::encode $user:$password]]
     set _state(-headers) [array get h]

     return [list $proxy(host) $proxy(port)]
 }

This will fail if autoproxy::user or autoproxy::password is not set. I should probably add a catch statement somewhere.

Category Package