summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <anton@sijanec.eu>2022-08-07 22:56:37 +0200
committerAnton Luka Šijanec <anton@sijanec.eu>2022-08-07 22:56:37 +0200
commitdcb7d6ef78f6c5ee118c23d56b55888a7916ac4f (patch)
tree550f4d27ddb49f820a6746cdadc890716dee2db4
parentsomewhat working http server (diff)
downloaddiscord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar.gz
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar.bz2
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar.lz
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar.xz
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.tar.zst
discord.tcl-dcb7d6ef78f6c5ee118c23d56b55888a7916ac4f.zip
-rwxr-xr-xwww.tcl15
1 files 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
</form>
"
}
- 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
}