spring_reference/IX. ‘How-to’ guides/64.17.1. Enable Tomcat’s HT...

15 lines
687 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

### 64.17.1. 启用Tomcat的HTTP响应压缩
Tomcat对HTTP响应压缩提供内建支持。默认是禁用的但可以通过application.properties轻松的启用
```java
server.tomcat.compression: on
```
当设置为`on`时Tomcat将压缩响应的长度至少为2048字节。你可以配置一个整型值来设置该限制而不只是`on`,比如:
```java
server.tomcat.compression: 4096
```
默认情况下Tomcat只压缩某些MIME类型的响应text/htmltext/xml和text/plain。你可以使用`server.tomcat.compressableMimeTypes`属性进行自定义,比如:
```java
server.tomcat.compressableMimeTypes=application/json,application/xml
```