libwww-perl / HTTP-Daemon

A simple http server class
http://metacpan.org/release/HTTP-Daemon/
Other
6 stars 16 forks source link

HTTP client hangs if zero-length file sent #54

Open mk90 opened 2 years ago

mk90 commented 2 years ago

https://github.com/libwww-perl/HTTP-Daemon/blob/b902312e478164bb5e8a9ab921cf6f5a7604a335/lib/HTTP/Daemon.pm#L546

Using send_file_response with empty file suppress "Content-Length" header line, because "if $size" contstruction treated as false.

Then library succsessfully complete operation with RC_OK code, but HTTP client waits data from server, and timeout occured as a result.

Removing "if $size" resolve this problem.

oalders commented 2 years ago

That's not great! @vanhoesel, do you know what the correct behaviour here is? Just send a Content-Length of 0? It's not clear to me what the use case is for sending an empty file.

ppisar commented 2 years ago

It depends on HTTP version and transfer encoding. But in general if the size is known to be 0, it should be indicated with "0". See https://www.ietf.org/rfc/rfc7230.html#section-3.3.2 for HTTP/1.1 and https://www.ietf.org/rfc/rfc1945.html#section-10.4 for HTTP/1.0.