Tcl Source Code

Artifact [9fed3f58ff]
Login

Artifact 9fed3f58fffb5c6acbf06ad921a77f432800c366a3efd5d8d25f2026d4f92803:

Attachment "keepalive.tcl" to ticket [cb0373bb33] added by sbron 2019-12-29 15:34:44. (unpublished)
package require http

# Redirect test page
set url http://jigsaw.w3.org/HTTP/300/301.html

# Make the HTTP library report what it is doing
namespace eval http #
proc http::Log {args} {
    puts [join $args]
}

set tok [http::geturl $url -keepalive 1]
if {[http::ncode $tok] in {301 302}} {
    # Determine the new URL
    set meta [http::meta $tok]
    set key [lsearch -exact -nocase -inline [dict keys $meta] location]
    set loc [dict get $meta $key]
    http::cleanup $tok
    puts "Redirecting to: $loc"
    set tok [http::geturl $loc -keepalive 1]
}
puts [http::code $tok]
http::cleanup $tok