simple-http-server icon indicating copy to clipboard operation
simple-http-server copied to clipboard

Content-Length 0 in HEAD Response

Open gurry opened this issue 6 years ago • 7 comments

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).

gurry avatar Jun 24 '18 06:06 gurry

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.

gurry avatar Jun 24 '18 07:06 gurry

Seems hyper or iron reset the ContentLength

A PR is welcome! : )

TheWaWaR avatar Jun 24 '18 13:06 TheWaWaR

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).

gurry avatar Jun 26 '18 11:06 gurry

It's an Iron bug. I've filed an issue there: https://github.com/iron/iron/issues/582

gurry avatar Aug 16 '18 06:08 gurry

Are you going to release a new Windows binary with this fix?

sergeevabc avatar Dec 23 '18 11:12 sergeevabc

Will have to move to the new version of Iron to get this fix released.

gurry avatar Dec 27 '18 04:12 gurry

This issue is still not fixed in version 0.6.2.

image

recolic avatar Aug 01 '22 11:08 recolic