Posted to tcl by aspect at Tue Oct 08 22:09:53 GMT 2019view pretty
method DoOutput {} { my variable reply_body chan if {$chan eq {}} return catch { # I'm pretty sure you can't sent utf-8 in headers anyway, but let's roll with it chan configure $chan -encoding utf-8 -translation {auto crlf} set length [string length $reply_body] if {[string length $reply_body] ne ""} { # content-length is in bytes set body [encoding convertto utf-8 $reply_body] set length [string length $reply_body] my reply set Content-Length $length # headers are sent in whatever encoding you like, with crlf chan puts $chan [my reply output] # body is sent in binary, with no line ending translation chan configure $chan -translation binary chan puts $chan $body } else { chan puts $chan [my reply output] } catch {chan flush $chan} my log HttpAccess {} } }