kristapsdz / kcgi

minimal CGI and FastCGI library for C/C++
https://kristaps.bsd.lv/kcgi
ISC License
270 stars 40 forks source link

304 sends non empty body with gzip #66

Open tedu opened 5 years ago

tedu commented 5 years ago

304 responses should not have a body. However, when kcgi enables gzip, it compresses the empty body and responds with a 14 byte gzip header.

Probably shouldn't compress empty body regardless of response code.

kristapsdz commented 5 years ago

The Internet is really unhelpful dealing with this situation!

First, it's straightforward to make sure that gzflush() isn't called if no data was written, but zero-length content with gzip compression is technically invalid gzip, so empty content would be an error in this case. However, according to this thread, it might be technically correct after all...?

Meanwhile, you can force the issue with khttp_body_compress(0) with your 304s, which will disable compression for the call and have a zero-length body unless you, you know, wrote some data.

Seems like the best thing to do is to see what big servers are doing in this case (asking for compression and a 304). Do they 304 with gzip and zero content? Do they 304 without gzip?