diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2024-06-29 13:04:11 +1000 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2024-06-29 13:04:11 +1000 |
commit | 252ad2b3446457e95fb7bb41829bc24304090232 (patch) | |
tree | 0adecce0b3628815b69339f03a282d0c61e5739c | |
parent | 7635f08fdeacdc3758ab410ae39c51529c614453 (diff) |
Can now send binary data
-rwxr-xr-x | http.tcl | 25 |
1 files changed, 9 insertions, 16 deletions
@@ -53,26 +53,19 @@ namespace eval http { set packet {} while { [gets $channel line] } { puts $line - puts -nonewline "field-line...";#!!!!!!!!!!!!! - flush stdout ## Check if field-line is in correct form. ## ^field-name : OWS field-value OWS $ if [expr ![regexp {^[[:alpha:]-]+(:){1}[[:space:]]?[[:print:]]+[[:space:]]?$} $line]] { respond $channel 400 } - puts " fine!";#!!!!!!!!!!!!! - puts -nonewline "Host duplicates...";#!!!!!!!!!!!!! ## Reject duplicates of the host field. set key [string tolower [string range $line 0 [expr [string first : $line] - 1]]] - puts -nonewline "key is $key ... [string compare $key host] and [lsearch $packet host] ...";#!!!! - flush stdout if [expr ([string compare $key "host"] == 0) && ([lsearch $packet "host"] != -1)] { respond $channel 400 } - puts " fine!";#!!!!!!!!!!!!! ## Add to packet dictionary dict append packet \ [string tolower [string range $line 0 [expr [string first : $line] - 1]]] \ @@ -85,23 +78,21 @@ namespace eval http { } - ## (3) If all is good, then respond. - puts "All good!" + ## (3) Find if the file exists, or there is a hooked application. # If file exists, then 200 OK! set filename [string cat $root [request_target::file $request_target]] - puts "Getting file $filename" - if [file exists $filename] { - respond $channel 200 $filename + if [expr [file exists $filename] && [file isfile $filename]] { + respond $channel 200 $filename + } elseif [expr [file exists [string cat $filename "index.html"]] && [file isfile [string cat $filename "index.html"]]] { + respond $channel 200 [string cat $filename "index.html"] } - #TODO: Make some filler for this. # If it's one of the targets of the imported namespace, then 200 OK! - #if [namespace eval $hook_namespace [string cat {lsearch $targets } "$filename"]] { + #elseif [namespace eval $hook_namespace [string cat {lsearch $targets } "$filename"]] { # respond $channel 200 $filename #} - puts "Actually, 404" - # Then I guess it doesn't exist. + ## Otherwise, 404. respond $channel 404 } @@ -115,6 +106,8 @@ namespace eval http { #TODO: configure it to try the cache. #TODO: configure channels to use binary translation if content type is not text/* set file [open $filename] + fconfigure $file -translation binary + fconfigure $channel -translation binary fcopy $file $channel close $file } |