Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: e33e69f6c15afd36f827c1260fca417f94f63eac
Ticket: 1173760fffffffffffffffffffffffffffffffff
geturl fails on https requests if a proxy server is used
User & Date: melissachawla on 2005-03-31 01:40:24
Changes

  1. assignee changed to: "hobbs"
  2. cmimetype changed to: "text/plain"
  3. comment changed to:
    Package require http
    I tried to use http::geturl on an https url with a proxy 
    server, and I kept getting timeouts (or ran forever when 
    no timeout was specified).
    
    package require http
    package require tls
    http::config -proxyhost <my-squid-host> -proxyport <my-
    squid-port> 
    http::register https 443 ::tls::socket http::geturl 
    https://<server>:443/<path> -timeout 30000
    
    Currently, the http package will use a GET request via 
    HTTPS to a web server outside my firewall via a web 
    proxy server inside my firewall.  I am sure that the web
    proxy server works because I can use it to make the 
    same request through my browser.  The problem is that 
    http package needs to make a "CONNECT" request to 
    the proxy before making the GET request.  I believe that 
    http version 2.4 is affected in the same way.  Here's a 
    description of the fix that I used:
    
    1) replace the following line in http.tcl:
    
            set conStat [catch {eval $defcmd $async {$phost 
    $pport}} s]
    
    with:
    
            if {[string equal -nocase $proto "https"] \
                    && [string match "*tls::socket" $defcmd]} {
                # Use "connect" to initiate https connection via 
    web proxy. 
                set conStat [catch {SecureProxyConnect 
    $phost $pport $host $port} s]
            } else {
                set conStat [catch {eval $defcmd $async 
    {$phost $pport}} s]
            }
    
    2) Add the SecureProxyConnect procedure:
    
    # Internal procedure to initiate https connection via 
    proxy server.
    proc http::SecureProxyConnect {proxyserver proxyport 
    webserver webserverport} {
         set sock [socket $proxyserver $proxyport]
         fconfigure $sock -blocking 0 -buffering line -
    translation crlf
    
         puts $sock "CONNECT $webserver:$webserverport 
    HTTP/1.1"
         puts $sock "Host: $webserver"
         puts $sock "User-Agent: [http::config -useragent]"
         puts $sock "Proxy-Connection: keep-alive"
         puts $sock "Connection: keep-alive"
         puts $sock ""
    
         fileevent $sock readable {set proxy_readable ""}
         global proxy_readable
         vwait proxy_readable
         fileevent $sock readable {}
    
         set block [read $sock]
         set result [lindex [split $block \n] 0]
         set code [lindex [split $result { }] 1]
         fconfigure $sock -blocking 1 -translation binary -
    buffering none
    
         if {$code >= 200 && $code < 300} {
             tls::import $sock
         } else {
             error "proxy connect failed: $block"
         }
         return $sock
    }
    
    
  4. foundin changed to: "obsolete: 8.3.4"
  5. priority changed to: "5 Medium"
  6. resolution changed to: "None"
  7. status changed to: "Open"
  8. submitter changed to: "melissachawla"
  9. subsystem changed to: "29. http Package"
  10. title changed to:
    geturl fails on https requests if a proxy server is used
    
  11. type changed to: "Bug"