Hello,
I have found a potential bug with ns_httpget.
It only seems to occur when ns_httpget'ing from a slow server.
The problem is that nowhere in ns_httpget or _ns_http_read is the socket
being checked for EOF -- the data returned from _ns_http_read is only
checked to see if it's empty.
I'm using AOLserver 4.02 and in particular http.tcl 1.13.
Affected code is in ns_httpget, http.tcl lines 339 - 343:
while {1} {
set buf [_ns_http_read $timeout $rfd $length]
append page $buf
if {[string match "" $buf]} {
break
}
....
}
and _ns_http_read, http.tcl lines 399 - 409:
proc _ns_http_read {timeout sock length} {
set buf ""
set nread [_ns_http_readable $timeout $sock]
if {$nread > 0} {
if {$length > 0 && $length < $nread} {
set nread $length
}
set buf [read $sock $nread]
}
return $buf
}
If the remote end has not returned data by the time of the next call to
_ns_http_read, nread will be 0, and an empty buf variable will be
returned. In ns_httpget, an empty buf stops further reading.
My fix was to change ns_httpget's
if {[string match "" $buf]} {
to
if {[eof $rfd]} {
This way, reading will continue until an explicit EOF is received from
[read].
Consider an example:
Current implementation:
HTTP/1.0 200 OK:
content-type = application/xml
content-length = 2852
[28/Jan/2004:12:45:29][6639.9][-conn:server1::0] Error:
_ns_http_read: nread: '1278', length: '2852'
[28/Jan/2004:12:45:29][6639.9][-conn:server1::0] Error:
_ns_http_read: nread: '1350', length: '1574'
[28/Jan/2004:12:45:30][6639.9][-conn:server1::0] Error:
_ns_http_read: nread: '0', length: '224'
Using above fix:
HTTP/1.0 200 OK:
content-type = application/xml
content-length = 2824
[28/Jan/2004:13:08:19][6657.9][-conn:server1::0] Error:
_ns_http_read: nread: '1278', length: '2824'
[28/Jan/2004:13:08:19][6657.9][-conn:server1::0] Error:
_ns_http_read: nread: '1350', length: '1546'
[28/Jan/2004:13:08:19][6657.9][-conn:server1::0] Error:
_ns_http_read: nread: '0', length: '196'
[28/Jan/2004:13:08:19][6657.9][-conn:server1::0] Error:
_ns_http_read: nread: '196', length: '196
The first three lines are the output of ns_set print, called from within
ns_httpopen. The last three lines are debug output from _ns_http_read.
The 'nread' value is the number of characters available to be read off
the socket, as returned via ns_socknread (via _ns_http_readable).
The 'length' value is the amount of data (content-length) minus what's
already been read.
As you can see, the remote end hasn't returned data yet by the time of
the third call to _ns_http_read. In the current implementation, this is
treated as an implicit EOF, and we're done reading, while still 224
bytes short of the content length.
Does anyone have any thoughts regarding this change? Is it something
that should be submitted as a patch?
Thanks,
Ross
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.