Posted to tcl by aspect at Tue Oct 08 22:09:53 GMT 2019view raw

  1. method DoOutput {} {
  2. my variable reply_body chan
  3. if {$chan eq {}} return
  4. catch {
  5. # I'm pretty sure you can't sent utf-8 in headers anyway, but let's roll with it
  6. chan configure $chan -encoding utf-8 -translation {auto crlf}
  7.  
  8. set length [string length $reply_body]
  9. if {[string length $reply_body] ne ""} {
  10. # content-length is in bytes
  11. set body [encoding convertto utf-8 $reply_body]
  12. set length [string length $reply_body]
  13. my reply set Content-Length $length
  14. # headers are sent in whatever encoding you like, with crlf
  15. chan puts $chan [my reply output]
  16. # body is sent in binary, with no line ending translation
  17. chan configure $chan -translation binary
  18. chan puts $chan $body
  19. } else {
  20. chan puts $chan [my reply output]
  21. }
  22. catch {chan flush $chan}
  23. my log HttpAccess {}
  24. }
  25. }
  26.