Compress

在将响应发送给客户端之前压缩响应

Compress

Compress中间件启用gzip压缩.

Configuration Examples

# Enable gzip compression
labels:
  - "traefik.http.middlewares.test-compress.compress=true"
# Enable gzip compression
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-compress
spec:
  compress: {}
# Enable gzip compression
- "traefik.http.middlewares.test-compress.compress=true"
"labels": {
  "traefik.http.middlewares.test-compress.compress": "true"
}
# Enable gzip compression
labels:
  - "traefik.http.middlewares.test-compress.compress=true"
# Enable gzip compression
[http.middlewares]
  [http.middlewares.test-compress.compress]
# Enable gzip compression
http:
  middlewares:
    test-compress:
      compress: {}

Info

在以下情况下压缩响应:

  • 响应主体大于1400个字节.
  • Accept-Encoding请求标头包含gzip .
  • 响应尚未压缩,即尚未设置Content-Encoding响应头.

Configuration Options

excludedContentTypes

excludedContentTypes指定一个内容类型列表,以便在压缩之前将传入请求的Content-Type标头与之进行比较.

具有在excludedContentTypes中定义的内容类型的请求不会被压缩.

内容类型以不区分大小写,忽略空格的方式进行比较.

labels:
  - "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: test-compress
spec:
  compress:
    excludedContentTypes:
      - text/event-stream
- "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"
"labels": {
  "traefik.http.middlewares.test-compress.compress.excludedcontenttypes": "text/event-stream"
}
labels:
  - "traefik.http.middlewares.test-compress.compress.excludedcontenttypes=text/event-stream"
[http.middlewares]
  [http.middlewares.test-compress.compress]
    excludedContentTypes = ["text/event-stream"]
http:
  middlewares:
    test-compress:
      compress:
        excludedContentTypes:
          - text/event-stream