I thought that I should answer myself a little bit. I have modified the current content of the http::geturl implementation to provide support for IPv6 addresses. My current version minimises the regexp parsing and adds a number of string operations. It's not perfect, but at least solve the issue. It stands as:
set URLmatcher {(?x) # this is _expanded_ syntax
^
(?: (\w+) : ) ? # <protocol scheme>
(?: //
( [^/\#?]+ ) # <location=userinfo + host + port>
)?
( / [^\#]*)? # <path> (including query)
(?: \# (.*) )? # <fragment>
$
}
# Phase one: parse, the URL match
if {![regexp -- $URLmatcher $url -> proto location srvurl]} {
unset $token
return -code error "Unsupported URL: $url"
}
if { [string first "@" $location] >= 0 } {
foreach {user hostport} [split $location "@"] break
} else {
set user ""
set hostport $location
}
set idx [string last ":" $hostport]
if { $idx >= 0 } {
set port [string trimleft [string range $hostport $idx end] ":"]
if { [string is integer $port] } {
set host [string trimright [string range $hostport 0 $idx] ":"]
} else {
set port ""
set host $hostport
}
} else {
set port ""
set host $hostport
}
# Phase two: validate
This is the only code that needs to be modified for doing the job. The idea is still not to do any check on the hostname (or IP in that case) and let the resolution fail when opening the socket.
I am biased. This code solves the problem, but is far from being elegant. I *think* that it covers all the cases and could then act as a replacement in the implementation. However, the http has cult status, it's existed for a long while, is widely tested and modifying it feels awkward. Any opinion, from an http.tcl expert?
/Emmanuel