Re: Who maintains Tclhttpd?



Jan Kandziora wrote:
Alexandre Ferrieux schrieb:

Maybe you mean "Content-Length" ?

Yes. Damn' brain-typo.


If yes, it is traced to tracker id 1929403:


https://sourceforge.net/tracker/index.php?func=detail&aid=1929403&group_id=10894&atid=110894

in this case, it is rather the http package's fault, doing a simple
[tell] on the channel after writing (hence subject to CRLF stuff)
instead of keeping track of actual counts. Thanks for adding any
insight there, I've gotten no answer to the questino "why" ?

I get truncation-errors only with error and authentication pages.

The culprit is (in version 3.5.1, around line 1560 in httpd.tcl)
---------
if [catch {
HdRespondHeader $sock text/html 1 [expr {[string length $message] + 4}]
$code
puts $sock ""
puts $sock $message
} err] {
Log $sock LostSocket $data(url) $err
}
Httpd_SockClose $sock $close
---------
This is clearly wrong, as it implies <puts $sock $message>, which is part of
the HTTP *data* will insert *exactly one* CRLF into the output. For the
above case, this is only true if $message has no \n (which is then
translated to CRLF!) inside. Second, it must be "string bytelength" instead
of "string length", as the output page may be encoded in utf-8 or other
multi-byte encoding.

Instead, it should read
---------
if [catch {
HttpdRespondHeader $sock text/html 1 [string bytelength $message] $code
puts $sock ""
fconfigure $sock -translation lf
puts -nonewline $sock $message
} err] {
Log $sock LostSocket $data(url) $err
}
Httpd_SockClose $sock $close
---------


It sounds like the fconfigure probably is right.

I wonder if this is any better:
set utf8msg [encoding convertto utf-8 $message]

HttpdRespondHeader $sock text/html 1 [string length $utf8msg] $code
...
puts -nonewline $sock $utf8msg


The [string length $utf8msg] should be the same as [string bytelength
$message] as I understand it, and my testing confirms that with
multibyte characters.

With Tcl's internal encoding being very similar to utf-8 it may
not matter though.


George
.



Relevant Pages

  • shell : is syntax checking via option -n really working ?
    ... # SecPanel - ListServer ... gets $sock passandport ... puts "Wrong authentication from ListClient \nHad to reject connection" ...
    (Debian-User)
  • Re: Tcl UDP Server vs Python UDP server, not good....
    ... Also changing the server reply to a puts to stdio, seems to suggest that the call-back sendTime is being invoked twice for each message received from client. ... proc sendTime {sock} { ... set peer [fconfigure $sock -peer] ...
    (comp.lang.tcl)
  • Cant figure out whats preventing the full message to send on the socket
    ... Please look over the below driver script and tell me where I'm going ... socket on the server socket in TCL, ... puts $logFile $str ... proc Accept {sock addr port} { ...
    (comp.lang.tcl)
  • imap client
    ... I/O on all channels, including stdin. ... fileevent $sock writable ... puts $data ... set mainevent putsfailure ...
    (comp.lang.tcl)
  • Tcl imap client
    ... I/O on all channels, including stdin. ... fileevent $sock writable ... puts $data ... set mainevent putsfailure ...
    (comp.mail.imap)