| Ticket UUID: | 29ff5c3abd4a55280297fb1e9da19450e14270f9 | |||
| Title: | autoproxy stopped working with tcl-tls on Tcl-9.x | |||
| Type: | Bug | Version: | ||
| Submitter: | umlaeute | Created on: | 2026-07-29 16:44:49 | |
| Subsystem: | http :: autoproxy | Assigned To: | oehhar | |
| Priority: | 5 Medium | Severity: | Minor | |
| Status: | Open | Last Modified: | 2026-11-16 15:24:13 | |
| Resolution: | None | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
I noticed that I cannot use autoproxy together with tcl-tls on Tcl-9.x. it was working nicely on Tcl-8.x this simple example from the docs: ~~~ package require http package require tls package require autoproxy autoproxy::init http::register https 443 ::autoproxy::tls_socket set tok [http::geturl https://google.com/] ~~~ gives the following error: > can't read "Uhost": no such variable on Linux this is with: Tcl/Tk 9.0.4 http 2.10.2 autoproxy 1.8.1 tls 2.0.1 on Windows (and macOS), this is with: Tcl/Tk 9.0.1 http 2.10.0 autoproxy 1.8.1 tls 2.0.1 i didn't thorougly test on macOS, as my setup there is rather convolved. in my application, on Linux and Windows i get an error (which i can catch), whereas on macOS it will simply crash because of "some issue", which I assume to be the same. | |||
| User Comments: |
oehhar added on 2026-11-16 15:24:13:
Brian, do you agree with the patch? And you are a tcllib group developper naw ;-). Take care, Harald oehhar added on 2026-11-16 15:22:09: The patch is effective. Andreas, you may merge this branch. Thanks for all, Harald serhiy.storchaka added on 2026-11-15 13:36:40: Proposed fix in branch autoproxy-tls-socket-tcl9. http 2.10 calls the registered socket command from http::OpenSocket at global level, so the upvar of host and state in autoproxy::tls_socket sees the wrong variables. The branch takes the target from state(socketinfo). It still depends on http internals, as discussed above; a proper interface in http would be better. autoproxytls.test now runs the tls tests with a fake tls package; two of them fail on 9.1 without the fix. bohagan added on 2026-11-12 01:08:55: My registration failed since I didn't get the email to confirm my account, so I can't push a fix. So here's a quick hack that seems to work. Replace ::autoproxy::tls_socket with this:
proc ::autoproxy::tls_socket {args} {
variable options
# Look into the http package for the actual target. If a proxy is in use then
# The function appends the proxy host and port and not the target.
if {[package vsatisfies [package require http] 2.10-]} {
upvar 2 state state
lassign [split $state(socketinfo) ":"] uhost uport
} else {
upvar host uhost port uport
upvar state state
}
set args [lrange $args 0 end-2]
lappend args $uhost $uport
set s [eval [linsert $args 0 tls_connect]]
# record the tls connection status in the http state array.
if {$options(tls_package) eq "twapi"} {
# With twapi::tls_socket, state may not be available on
# an async connect until negotiation is completed.
set state(tls_status) ""
set security_context [fconfigure $s -context]
if {$security_context ne ""} {
set cert [twapi::sspi_remote_cert $security_context]
set cert_info [twapi::cert_info $cert]
twapi::cert_release $cert
dict set state(tls_status) issuer [dict get $cert_info -issuer]
dict set state(tls_status) subject [dict get $cert_info -subject]
dict set state(tls_status) notBefore [dict get $cert_info -start]
dict set state(tls_status) notAfter [dict get $cert_info -end]
# Note: binary encode hex was not available in older Tcl, use twapi::hex
dict set state(tls_status) serial [twapi::hex [dict get $cert_info -serialnumber]]
# TBD - dict set state(tls_status) cipher
# TBD - dict set state(tls_status) sbits
}
} else {
tls::handshake $s
set state(tls_status) [tls::status $s]
}
return $s
}
oehhar added on 2026-11-11 18:29:36: Well, the auto-configuration feature is only in autoproxy. The 9 http is able to do proxy authentication as new feature. But the issue is the tls connection... It is no obligation to make this work... Thanks for all, Harald bohagan added on 2026-11-11 18:09:27: Looking at the updated http package, I’m not sure autoproxy is needed anymore, at least for http sessions. There seem to be options that fulfill the need. I’ll leave it to the http package expert to confirm. oehhar added on 2026-11-11 15:16:21: Again from the core list: Harald: I find it critical that autoproxy depends on http internals. Brian: Agree. The issue is that http only passes the host and port to connect to for the proxy, but not the destination. Both packages need a new handler for the auto proxy case that passes both sets of variables. oehhar added on 2026-11-11 08:11:00: Brian O'Hagan answered on the core list: I don’t have a tcllib account or I would reply there. The variable uhost only exists in autoproxy::tks_socket as the alias for upvar variable host. So the issue is a missing var host in the caller’s procedure. I’d have to check the http package to see what changed there. THanks for all the answers, Harald apnadkarni added on 2026-11-11 03:38:35: Well, it looks like the implementation of http::geturl has completely changed in 9.0 to use coroutines and the variables "host" and "port" no longer exist at that frame in the call stack causing the upvar in autoproxy to fail. Sorry, can't help with a fix as this seems a http<->autoproxy interaction issue and I'm not familiar with either. oehhar added on 2026-11-10 10:52:49: Thanks. Verified with Tcl9.0.4 on MS_Win with twapi:
set modulePath {C:\test\fossil\tcllib\tcllib_main\modules}
foreach module {http uri base64} {
lappend auto_path [file join $modulePath $module]
}
% package require http
2.10.2
% package require autoproxy
1.8.1
% package require twapi
5.2.0
% autoproxy::init
% autoproxy::configure -tls_package twapi
% http::register https 443 autoproxy::tls_socket
% set tok [http::geturl https://google.com/]
can't read "uhost": no such variable
The related autoproxy.tcl code is as follows:
upvar host uhost port uport
set args [lrange $args 0 end-2]
lappend args $uhost $uport
The variable "uhost" and "uport" do not exist in http.tcl for 8.6 and 9.0. I have no idea, how this works in 8.6. But it works! With same twapi version. This might be that the new variable resolution to not check the global namespace might be the issue. But I have no idea. Sorry, Harald Sorry, Harald | |||
Home
Blog
Docs
Downloads
Tickets
Timeline
Branches
Tags
Wiki