ContentType

Handling Content-Type auto-detection

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.

Info

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).

Configuration Examples

Docker & Swarm

  1. # Enable auto-detection
  2. labels:
  3. - "traefik.http.middlewares.autodetect.contenttype=true"

Kubernetes

  1. # Enable auto-detection
  2. apiVersion: traefik.io/v1alpha1
  3. kind: Middleware
  4. metadata:
  5. name: autodetect
  6. spec:
  7. contentType: {}

Consul Catalog

  1. # Enable auto-detection
  2. - "traefik.http.middlewares.autodetect.contenttype=true"

File (YAML)

  1. # Enable auto-detection
  2. http:
  3. middlewares:
  4. autodetect:
  5. contentType: {}

File (TOML)

  1. # Enable auto-detection
  2. [http.middlewares]
  3. [http.middlewares.autodetect.contentType]

Configuration Options

autoDetect

Warning

autoDetect option is deprecated and should not be used. Moreover, it is redundant with an empty ContentType middleware declaration.

autoDetect specifies whether to let the Content-Type header, if it has not been set by the backend, be automatically set to a value derived from the contents of the response.