我已经配置了通过 AWS EC2 安装在 Linux 服务器上的 Tomcat 6.0,以压缩大型 JSON 对象响应(约 54k 大小)——但由于某种原因,它没有压缩它。
/usr/share/tomcat6/conf/server.xml 中的连接器定义 -
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" compression="force"
compressableMimeType="text/html,text/xml,text/plain,application/javascript,application/json,text/javascript,text/json"
redirectPort="8443" />
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="200" scheme="https" secure="true" compression="force"
compressableMimeType="text/html,text/xml,text/plain,application/javascript,application/json,text/javascript,text/json"
keystoreFile="/usr/share/tomcat6/conf/my.keystore" keystorePass="password"
clientAuth="false" sslProtocol="TLS" />
请求标头,接受 gzip -
POST /mycommand HTTP/1.1
Host: my.host.com
Proxy-Connection: close
Accept-Encoding: gzip
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Content-Length: 431
响应标头,在连接器中配置 MIME -
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json;charset=UTF-8
Vary: Accept-Encoding
Date: Mon, 27 Aug 2012 20:19:05 GMT
Connection: close
Content-Length: 55565
我试过了compressed="2048"
,同样的问题。
我在服务器上的命令方法是使用带有杰克逊 JAR 的 Spring MVC 来创建 JSON 响应 -
@RequestMapping(method=RequestMethod.POST, value="/mycommand")
public @ResponseBody BasicResponse doCommand(
...
}
任何的想法?