From dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 7 Aug 2022 22:56:37 +0200 Subject: fix www.tcl (it's never right on the first try) --- www.tcl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/www.tcl b/www.tcl index 2dcf976..e5cd36f 100755 --- a/www.tcl +++ b/www.tcl @@ -59,16 +59,17 @@ namespace eval www { my variable to_parse chan stage headers arguments uri path body switch $stage { headers { - if {[catch {append to_parse [read $chan]}] != 0} { + if {[catch {append to_parse [gets $chan]}] != 0} { my destroy } + append to_parse "\n" if {[string first "\n\n" $to_parse] != -1} { set raw_headers [split $to_parse "\n"] set i 0 foreach hdr [lreplace $raw_headers 0 0] { - lappend headers [string trim [lindex [split $hdr :] 0]] + lappend hdrs [string trim [lindex [split $hdr :] 0]] set value [lreplace [split $hdr :] 0 0] - lappend headers [string trim [join $value :]] + lappend hdrs [string trim [join $value :]] } set components {} @@ -79,8 +80,8 @@ namespace eval www { } set uri [lindex $components 1] - dict map {key value} $headers { - set key [string tolower $key] + dict for {key value} $hdrs { + dict append headers [string tolower $key] $value } set path [lindex [split $uri "?"] 0] @@ -101,7 +102,7 @@ namespace eval www { if {[catch {append to_parse [read $chan]}] != 0} { my destroy } - if {[string length to_parse] == [dict get $headers content-length]} { + if {[string length $to_parse] == [dict get $headers content-length]} { lappend arguments {*}[split $to_parse "%=;"] set body $to_parse set stage read @@ -163,7 +164,7 @@ Connection: close " } - server create s 8251 "/* [namespace which action]" + server create s 0 "/* [namespace which action]" puts "http://127.0.0.1:[s ports]/helloworld" vwait forever } -- cgit v1.2.3