Jersey 2 gzip压缩没有Content-Encoding标头作为响应

时间:2015-09-16 17:30:32

标签: java rest gzip jersey-2.0

我读过这个:compress-responses-in-jersey并且有泽西2配置:

    @ApplicationPath("/jaxrs/")
public class AppConfig extends ResourceConfig {

    public AppConfig() {
        super(AdvertisementResource.class, MultiPartFeature.class);
        packages("jaxrs");
        EncodingFilter.enableFor(this, GZipEncoder.class, DeflateEncoder.class);
    }
}

我有标题请求:

GET http://localhost:8081/jaxrs/admin-adblock
Accept:application/json
Cache-Control:no-cache
Content-Type:application/json
Authorization:Basic c21h... 
Accept-Encoding:gzip,deflate

但标题回复是:

HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Server: Jetty(9.2.2.v20140723)

如果我有以下内容,则只会显示Content-Encoding:gzip的回复Vary: Accept-Encoding标题:

EncodingFilter.enableFor(this, GZipEncoder.class, DeflateEncoder.class);

如果我删除压缩并注释EncodingFilter行响应头是:

HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Server: Jetty(9.2.2.v20140723)

或者这个:

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 369
Server: Jetty(9.2.2.v20140723)

我正在使用Intellij Rest Client Tool进行测试,我不确定是否收到服务器的压缩响应?

我已经下载了泽西源并设置断点here并使用Intellij调试休息服务Web应用程序,似乎在此处添加了CONTENT_ENCODING gzip:

response.getHeaders().putSingle(HttpHeaders.CONTENT_ENCODING, contentEncoding);

但它在Intellij Rest Client工具的响应头中缺失..

1 个答案:

答案 0 :(得分:0)

我已下载SoapUI并测试相同的Rest请求响应标头:

HTTP/1.1 200 OK
Content-Type: application/json
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 204
Server: Jetty(9.2.2.v20140723)

Intellij Rest Client工具隐藏了响应头Content-Encoding和Content-Length .. 我打开了新的issue