请求Content-Type为gzip时,Jetty会响应400 Bad Request [英] Jetty responds with 400 Bad Request when request Content-Type is gzip

查看:351
本文介绍了请求Content-Type为gzip时,Jetty会响应400 Bad Request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring MVC Java 1.8.0_45-b14 Jetty 9.3.0.v20150612 上运行的后端运行良好未压缩的请求,但无法接受压缩的请求。

Spring MVC Java 1.8.0_45-b14 backend running on Jetty 9.3.0.v20150612 is working well with uncompressed requests, but fails to accept compressed ones.

我遵循了Gzip Handler配置说明这里,确保 POST 请求也支持这些请求。虽然它没有说这个配置完全适用于请求......但它可能仅用于响应。

I've followed Gzip Handler configuration instructions here, made sure these are supported for POST requests as well. Though it doesn't say this configuration is at all for requests... it may be only for responses.

etc / jetty-gzip.xml -

etc/jetty-gzip.xml -

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Get id="next" name="handler" />
  <Set name="handler">
    <New id="GzipHandler" class="org.eclipse.jetty.server.handler.gzip.GzipHandler">
      <Set name="handler"><Ref refid="next" /></Set>
      <Set name="minGzipSize"><Property name="jetty.gzip.minGzipSize" deprecated="gzip.minGzipSize" default="2048"/></Set>
      <Set name="checkGzExists"><Property name="jetty.gzip.checkGzExists" deprecated="gzip.checkGzExists" default="false"/></Set>
      <Set name="compressionLevel"><Property name="jetty.gzip.compressionLevel" deprecated="gzip.compressionLevel" default="-1"/></Set>
      <Set name="excludedAgentPatterns">
        <Array type="String">
          <Item><Property name="jetty.gzip.excludedUserAgent" deprecated="gzip.excludedUserAgent" default=".*MSIE.6\.0.*"/></Item>
        </Array>
      </Set>

      <Set name="includedMethods">
        <Array type="String">
            <Item>GET</Item>
            <Item>POST</Item>
        </Array>
      </Set>

      <Set name="includedPaths">
        <Array type="String">
          <Item>/*</Item>
        </Array>
      </Set>

    </New>
  </Set>
</Configure>

在web.xml中 -

In web.xml -

<filter>
    <filter-name>GzipFilter</filter-name>
    <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>
    <init-param>
        <param-name>mimeTypes</param-name>
        <param-value>text/html,text/plain,text/xml,application/xhtml+xml,text/css,application/javascript,image/svg+xml,application/json</param-value>
    </init-param>
    <init-param>
        <param-name>minGzipSize</param-name>
        <param-value>500</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>GzipFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Android客户端会发生这种情况,并且还会使用HTTP客户端应用程序(Paw)进行重现,这是一个请求示例 -

This happens with an Android client and also reproduces with HTTP Client app (Paw), here's a request example -

POST /report?v=1 HTTP/1.1
Content-Encoding: gzip
Content-Type: application/json
Host: 10.0.0.1:8080
Connection: close
User-Agent: Paw/2.2.2 (Macintosh; OS X/10.10.4) GCDHTTPRequest
Content-Length: 5845

xí\MÇuÝûWÔE(É`_¦(<EtD&)%:¦OTè.EôÔU53¬¼ð"ÇYfÆ'®ì­/áÿʽ¯ª
r(ʲä#èúz÷Ý÷^5èýR;Úå;ÕÎÿöºÊuW«ß«v«ß¿ø³:VÕ)Õ .. BINARY ...

回复 -

HTTP/1.1 400 Bad Request
Content-Type: text/html;charset=iso-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 242
Connection: close

Jetty是否支持压缩请求?(无法找到明确的证据)

Does Jetty even support compressed requests? (couldn't find a clear evidence for that)

什么是我的配置有问题吗?

What's wrong with my config?

推荐答案

首先,从网上删除 GzipFilter .xml 它不再相关(从Jetty 9.3.0开始)

First, Remove GzipFilter from your web.xml it's not relevant anymore (starting with Jetty 9.3.0)

GzipHandler 是所有旧的基于过滤器的gzip过滤器的新替代品( GzipFilter AsyncGzipFilter IncludableGzipFilter )。

GzipHandler is the new replacement for all old filter based gzip filters (GzipFilter, AsyncGzipFilter, and IncludableGzipFilter).

它被设计为在连接流的基础上运行,这是基于过滤器的方法在异步I / O领域无法做到的。

It's been designed to function at a level more fundamental to the connection streams, something that the filter based approaches could not do in the world of Async I/O.

在Jetty 9.3.0中说... GzipHandler 只有针对Response主体内容设计的实现。 (就像之前的GzipFilters一样)

That being said ... GzipHandler in Jetty 9.3.0 only has an implementation designed for the Response body content. (Just like the GzipFilters of before)

然而,我们学到的是,有些项目扩展了我们的GzipFilter以添加Request内容体gzip处理。我们从GzipFilter到GzipHandler的更改中断了。

What we learned however, is that some projects extended our GzipFilter to add Request content body gzip handling as well. Which our change from GzipFilter to GzipHandler broke.

我们在 https://bugs.eclipse.org/471577 (DropWizard为自己的BiDiGzipFilter扩展了GzipFilter)

We have an open bug about that at https://bugs.eclipse.org/471577 (DropWizard extended GzipFilter for their own BiDiGzipFilter)

我们认识到可能存在Gzip在请求内容主体上的一些有用功能,但我们还没有实现。 (提示,提示,删除我们的补丁)

We recognize that there could be some useful functions for Gzip on the request content body, but we don't have an implementation for that yet. (hint, hint, drop a patch on us)

这篇关于请求Content-Type为gzip时,Jetty会响应400 Bad Request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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