Empty content from gziped http response

2019-09-07 00:36发布

I have implemented gziping content of response in a filter. If server is sending 200 response without any content is still adding content encoding header like

Content-Encoding:gzip
Content-Length:0

On the other side another filter is reading the response and is trying to create GZIPInputStream which will fail because content does not contain gzip header and footer. Question is which side is doing it wrong? Should producer not add "Content-Encoding:gzip"? Should producer add gzip header/footer to content? Or maybe should consumer recognize empty content and don't try to create GZIPInputStream? Browsers not have any problem with consuming such responses.

1条回答
Evening l夕情丶
2楼-- · 2019-09-07 00:55

I didn't try this special case but I think the producer side is ok because the response does not have content so Content-Length:0 is ok. But the consumer side is not ok when it try to create GZIPInputStream with nil content.

查看更多
登录 后发表回答