2022-04-15 13:44:08 +00:00
---
title: "Traefik ContentType Documentation"
2022-11-29 10:48:05 +00:00
description: "Traefik Proxy's HTTP middleware automatically sets the `Content-Type` header value when it is not set by the backend. Read the technical documentation."
2022-04-15 13:44:08 +00:00
---
2020-01-21 17:06:03 +00:00
# ContentType
2021-02-11 13:34:04 +00:00
Handling Content-Type auto-detection
2020-01-21 17:06:03 +00:00
{: .subtitle }
2022-11-29 10:48:05 +00:00
The Content-Type middleware sets the `Content-Type` header value to the media type detected from the response content,
when it is not set by the backend.
2020-01-21 17:06:03 +00:00
!!! info
2020-04-29 09:26:04 +00:00
The scope of the Content-Type middleware is the MIME type detection done by the core of Traefik (the server part).
Therefore, it has no effect against any other `Content-Type` header modifications (e.g.: in another middleware such as compress).
2020-01-21 17:06:03 +00:00
## Configuration Examples
2023-05-10 13:28:05 +00:00
```yaml tab="Docker & Swarm"
2022-11-29 10:48:05 +00:00
# Enable auto-detection
2020-01-21 17:06:03 +00:00
labels:
2022-11-29 10:48:05 +00:00
- "traefik.http.middlewares.autodetect.contenttype=true"
2020-01-21 17:06:03 +00:00
```
```yaml tab="Kubernetes"
2022-11-29 10:48:05 +00:00
# Enable auto-detection
2023-03-20 14:38:08 +00:00
apiVersion: traefik.io/v1alpha1
2020-01-21 17:06:03 +00:00
kind: Middleware
metadata:
name: autodetect
spec:
2022-11-29 10:48:05 +00:00
contentType: {}
2020-01-21 17:06:03 +00:00
```
```yaml tab="Consul Catalog"
2022-11-29 10:48:05 +00:00
# Enable auto-detection
- "traefik.http.middlewares.autodetect.contenttype=true"
2020-01-21 17:06:03 +00:00
```
```yaml tab="File (YAML)"
2022-11-29 10:48:05 +00:00
# Enable auto-detection
2020-01-21 17:06:03 +00:00
http:
middlewares:
autodetect:
2022-11-29 10:48:05 +00:00
contentType: {}
2020-01-21 17:06:03 +00:00
```
2021-06-18 22:08:08 +00:00
```toml tab="File (TOML)"
2022-11-29 10:48:05 +00:00
# Enable auto-detection
2021-06-18 22:08:08 +00:00
[http.middlewares]
[http.middlewares.autodetect.contentType]
2022-12-19 09:42:05 +00:00
```