Luukdegram / apple_pie

Basic HTTP server implementation in Zig
MIT License
163 stars 21 forks source link

Add Content-Length Header field if the response is empty #63

Closed joachimschmidt557 closed 3 years ago

joachimschmidt557 commented 3 years ago

According to the spec, a Content-Length of zero is allowed. Furthermore, according to the spec, when not supplying Content-Length, the server must close the connection in order to signal the end of the response, which is not always the case (as keep-alive may be enabled). So the best solution would be to include the Content-Length header even if the response is empty.

Luukdegram commented 3 years ago

Thanks. There are actually a few cases where we must not emit this header at all. I'm planning to rewrite the entire Response logic, but your fix will at least ensure that http clients will not wait infinitely for the server to close the connection on empty bodies. Thanks once again!