Overview
| Artifact ID: | 2e2db1be48bd554d08ea1a4d35daadf0e3b6f7fc0a48a56815d7ec4a0f4857a4 |
|---|---|
| Ticket: | 1173760fffffffffffffffffffffffffffffffff
geturl fails on https requests if a proxy server is used |
| User & Date: | kjnash on 2022-10-26 12:56:58 |
Changes
- closedate changed to: "2459879.03956938"
- closer changed to: "kjnash"
- 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 } - icomment:
This is now fixed in Tcl 8.7, fossil branch core-8-branch, commit [f0cf5f7866]. The fix is based on the changes proposed above, plus proxy authentication as used in (Tcllib) autoproxy, and handling of proxy errors by returning the proxy's HTTP response.
- login: "kjnash"
- mimetype: "text/x-fossil-plain"
- resolution changed to: "Fixed"
- severity changed to: "Minor"
- status changed to: "Closed"