从gziped的http响应中清空内容 [英] Empty content from gziped http response

查看:110
本文介绍了从gziped的http响应中清空内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在过滤器中实现了gziping的响应内容。如果服务器发送200响应没有任何内容仍然添加内容编码头像

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

另一方面,另一个过滤器正在读取响应,并试图创建GZIPInputStream,将会失败,因为内容不包含gzip页眉和页脚。
问题是哪一边做错了?生产者是否添加Content-Encoding:gzip?生产者应该向内容添加gzip header / footer吗?或者也许应该消费者识别空的内容,不要尝试创建GZIPInputStream?浏览器在消费此类响应时没有任何问题。

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.

推荐答案

我没有尝试这种特殊情况,但我认为生产者方是好的,因为响应没有内容,所以Content-Length:0可以。
但是尝试用nil内容创建GZIPInputStream时,消费者端就不行。

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.

这篇关于从gziped的http响应中清空内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆