Kof*_*Kof 1 java http jetty spring-mvc
Java 1.8.0_45-b14运行的Spring MVC 后端在Jetty 9.3.0.v20150612未压缩的请求中运行良好,但无法接受压缩的请求.
我在这里遵循了Gzip Handler配置说明,确保这些POST请求也受支持.虽然它没有说这种配置完全适用于请求......但它可能仅用于响应.
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>
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
Android客户端会发生这种情况,并且还会使用HTTP客户端应用程序(Paw)进行重现,这是一个请求示例 -
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 ...
Run Code Online (Sandbox Code Playgroud)
回应 -
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
Run Code Online (Sandbox Code Playgroud)
Jetty甚至支持压缩请求吗?(找不到明确的证据)
我的配置有什么问题?
First, Remove GzipFilter from your web.xml it's not relevant anymore (starting with Jetty 9.3.0)
GzipHandler is the new replacement for all old filter based gzip filters (GzipFilter, AsyncGzipFilter, and IncludableGzipFilter).
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.
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)
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.
We have an open bug about that at https://bugs.eclipse.org/471577 (DropWizard extended GzipFilter for their own BiDiGzipFilter)
我们认识到Gzip在请求内容体上可能有一些有用的功能,但我们还没有实现.(提示,提示,删除我们的补丁)
| 归档时间: |
|
| 查看次数: |
1629 次 |
| 最近记录: |