# myhttp.tcl - Playing HTTP if 0 {[Richard Suchenwirth] 2004-02-14 - After being online at home, I felt I had to learn some more about the Hypertext Transfer Protocol (HTTP) that drives the Web. Tcl has good support with the [http] package, so I didn't need to walk the last steps to the [socket] invocation myself, but concentrate on what comes back after a HTTP GET, especially the headers. So here's my HTTP plaything, the ugliest browser I've seen in a long time, because it does not try to render HTML, just displays the plain text that came. However, it is still interesting, for looking behind the glittering facades of "real" browsers... You have an entry on top, in which to type an URL, and the text at bottom displays what came back after you hit , images being rendered via the great [Img] extension, everything else as plain text. } package require http package require Img package require base64 pack [entry .e -textvar e] -fill x -expand 1 bind .e {go .f.t $e} pack [frame .f] -fill both -expand 1 pack [scrollbar .f.y -command ".f.t yscroll"] -fill y -side right pack [text .f.t -wrap word -yscrollc ".f.y set"] \ -fill both -expand 1 -side right foreach i {red blue green3} {.f.t tag config $i -foreground $i} focus .e raise . proc go {w url} { set token [http::geturl $url] upvar #0 $token arr $w see end $w insert end \n$arr(url) blue if [info exists arr(error)] {$w insert end \n$arr(error) red} $w insert end \n$arr(meta) green3 if [regexp {Content-Type image/([^ ]+)} $arr(meta) -> format] { set im [image create photo -data [base64::encode $arr(body)]] $w insert end \n $w image create end -image $im } else { $w insert end \n$arr(body) } http::cleanup $token } bind . {exec wish $argv0 &; exit} ---- [Arts and crafts of Tcl-Tk programming]