From ab2659b28592bfdb4d03365ddcd39bf5c6f7ae2f Mon Sep 17 00:00:00 2001 From: Jacob Haip Date: Wed, 22 Mar 2023 23:10:20 -0400 Subject: fix handling of web response with contentType and body --- web.tcl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web.tcl b/web.tcl index e3c7fb32..0a95f6b7 100644 --- a/web.tcl +++ b/web.tcl @@ -96,24 +96,24 @@ proc handleRead {chan addr port} { if {$response ne "" && [dict exists $response raw]} { puts -nonewline $chan [dict get $response raw] } else { - set response {} + set finalResponse {} if {$html ne ""} { - set response $html + set finalResponse $html } elseif {$response ne ""} { if {[dict exists $response contentType]} { set contentType [dict get $response contentType] } if {[dict exists $response body]} { - set response [dict get $response body] + set finalResponse [dict get $response body] } else { - set response "error missing body" + set finalResponse "error missing body" } } else { - set response [handlePage $path contentType] + set finalResponse [handlePage $path contentType] } puts -nonewline $chan "HTTP/1.1 200 OK\nConnection: close\nContent-Type: $contentType\n\n" chan configure $chan -encoding binary -translation binary - puts -nonewline $chan $response + puts -nonewline $chan $finalResponse } close $chan } elseif {[::websocket::test $::serverSock $chan "/ws" $headers]} { -- cgit v1.2.3