ContentType
当后端未设置 Content-Type 头时,contentType 中间件会将其值设置为从响应内容中检测到的媒体类型,
此行为仅发生在后端没有设置该头的情况下。
提示
contentType 中间件仅在 Traefik 检测 MIME 类型时生效。如果任何中间件(例如 Headers 或 Compress)在链中任意位置设置了 contentType 头,contentType 中间件就不会生效。
配置示例¶
# Enable auto-detection
http:
middlewares:
autodetect:
contentType: {}# Enable auto-detection
[http.middlewares]
[http.middlewares.autodetect.contentType]# Enable auto-detection
labels:
- "traefik.http.middlewares.autodetect.contenttype=true"// Enable auto-detection
{
// ...
"Tags": [
"traefik.http.middlewares.autodetect.contenttype=true"
]
}# Enable auto-detection
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: autodetect
spec:
contentType: {}