Skip to content

Traefik proxy plugin to extract HTTP header value and create a new header with extracted value

License

Notifications You must be signed in to change notification settings

i-fulfilment/copy-header-value-traefik-plugin

Repository files navigation

Copy header value Traefik plugin

Traefik plugin that copies HTTP header value with format key1=value1; key2=value2 into a new header. Motivation for this plugin is to be able to extract a particular key's value from Cookie header. However, it can be adapted for other purposes taking into account this plugin's limitations, e.g. only a single key's value can be copied.

Configuration

Traefik static configuration for plugin:

...
experimental:
  plugins:
    copy-header-value:
      moduleName: github.com/argyle-engineering/copy-header-value-traefik-plugin
      version: v1.0.0

Plugin is then configured as a route middleware

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: copy-header-value
spec:
  plugin:
    copy-header-value:
      from: "Cookie"
      pairSeparator: ";"
      keyValueSeparator: "="
      key: "id"
      to: "Authorization"
      prefix: "Bearer "
      overwrite: false

In this example, when there is Cookie header, value identified by the id key will be moved into Authorization header with Bearer as a value prefix. In case Authorization header already exists, overwrite controls whether it will be overwritten with the value extracted from Cookie header.

About

Traefik proxy plugin to extract HTTP header value and create a new header with extracted value

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages