# If using twapi 4.9.2 and http 2.10b1, the following error message is generated:
# Invalid option '-type'.
# Must be one of -myaddr, -myport, -async, -socketcmd, -server, -peersubject, -requestclientcert, -credentials, -verifier
#
# This seems to be caused by the new option "-type $token" when creating the openCmd:
# set state(openCmd) [list {*}$defcmd {*}$sockopts -type  $token {*}$targetAddr]
#
# If I remove the "-type" option, everything works as it did with http 2.10a1 or 2.9.8.
# set state(openCmd) [list {*}$defcmd {*}$sockopts {*}$targetAddr]
# If using tls, everything works as expected.

set useTwapi true

package require http

puts "Tcl  : [info pa]"
puts "http : [package version http]"

if { $useTwapi } {
    package require twapi
    http::register https 443 [list ::twapi::tls_socket]
    puts "twapi: [package version twapi]"
} else {
    package require tls
    http::register https 443 [list ::tls::socket]
    puts "tls  : [package version tls]"
}

set token [http::geturl "https://www.tcl3d.org/bawt/"]

upvar #0 $token state
puts "state(url)  = $state(url)"
puts "state(http) = $state(http)"
puts "state(type) = $state(type)"

http::cleanup $token
