traefik_conditional_headers

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Conditional Headers Plugin for Traefik

Set request headers conditionally based on the incoming hostname. Supports multiple hosts sharing the same headers.

Features

  • Multiple hosts can share the same header configuration
  • Supports exact host matching
  • Supports wildcard subdomain matching (e.g., *.demo.dev.io)
  • First matching rule wins

Configuration

Multiple hosts with same headers:
http:
  middlewares:
    my-conditional-headers:
      plugin:
        conditional-headers:
          rules:
            - hosts:
                - demo.dev.io
                - test.demo.dev.io
                - staging.demo.dev.io
              headers:
                X-App-Kernel-Name: demo.valksor.com
                X-Environment: production
            - hosts:
                - prod.example.com
              headers:
                X-App-Kernel-Name: prod.example.com
                X-Environment: production
With wildcards:
http:
  middlewares:
    my-conditional-headers:
      plugin:
        conditional-headers:
          rules:
            - hosts:
                - "*.internal.dev.io"
              headers:
                X-App-Kernel-Name: internal.valksor.com
            - hosts:
                - "*.public.dev.io"
              headers:
                X-App-Kernel-Name: public.valksor.com

Docker Compose Labels

labels:
  - "traefik.http.middlewares.my-headers.plugin.conditional-headers.rules[0].hosts[0]=demo.dev.io"
  - "traefik.http.middlewares.my-headers.plugin.conditional-headers.rules[0].hosts[1]=test.demo.dev.io"
  - "traefik.http.middlewares.my-headers.plugin.conditional-headers.rules[0].hosts[2]=staging.demo.dev.io"
  - "traefik.http.middlewares.my-headers.plugin.conditional-headers.rules[0].headers.X-App-Kernel-Name=demo.valksor.com"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

Types

type Config

type Config struct {
	Rules []Rule `json:"rules"`
}

func CreateConfig

func CreateConfig() *Config

type Rule

type Rule struct {
	Hosts   []string          `json:"hosts"` // Multiple hosts
	Headers map[string]string `json:"headers"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL