simple-http-server
simple-http-server copied to clipboard
Content-Length 0 in HEAD Response
If I try a HEAD
request on any file that simple_http_server
is serving, it always returns the Content-Length
header with value 0. If I try the GET request on the same file, it returns the correct value in that header. HEAD
is often used by many file downloading software to determine the length of the file before downloading it. This would break them (as it's doing in my case).
A quick debugging session showed that we're setting the content length correctly for HEAD
requests:
https://github.com/TheWaWaR/simple-http-server/blob/108275b77217c8c5bfe90671d7d50ea1b2c9e2d7/src/main.rs#L683
which is identical to how we set it for GET
requests:
https://github.com/TheWaWaR/simple-http-server/blob/108275b77217c8c5bfe90671d7d50ea1b2c9e2d7/src/main.rs#L781
Yet it works for GET
and doesn't work for HEAD
. What gives?
I also saw in the debugger that the metadata
field does contain the correct length read from the file system for HEAD
.
Seems hyper
or iron
reset the ContentLength
A PR is welcome! : )
Thanks @TheWaWaR.
I agree with you. I should've ideally done the fix, but I'm in the middle of a lot of stuff right now. So will have to do this later (unless someone beats me to it).
It's an Iron bug. I've filed an issue there: https://github.com/iron/iron/issues/582
Are you going to release a new Windows binary with this fix?
Will have to move to the new version of Iron
to get this fix released.
This issue is still not fixed in version 0.6.2
.