Skip to content

Re-use variable from HostRegexp in another label #5030

@sgohl

Description

@sgohl

Do you want to request a feature or report a bug?

Feature

What did you expect to see?

Assume a Host Rule like this (docker-compose style):

    labels:
      - "traefik.frontend.rule=HostRegexp:{portal:.+}.example.org"

An application serves multiple portals and the application must know which portal it is serving. This information should be extracted from the requested Host.
Currently, I must spawn a service for every portal and set the header statically, like this:

      - "traefik.frontend.headers.customRequestHeaders=portal:something"

It would be a very helpful feature to dynamically reuse the previously regex'd match as a variable here, in place of something.

There are multiple portals plus portal-specific api, plus microservices, all needing the portal information, so it's growing very fast.

nginx provides what I want to achieve with the following syntax:

server_name ~^(?<portal>.+?)\.example\.org$;
proxy_set_header PORTAL "$portal";

The application behind then can read the HTTP header PORTAL and behave accordingly.

As a proposal, I could imagine a go-like syntax:

      - "traefik.frontend.headers.customRequestHeaders=portal:{{portal}}"

Maybe this can be achieved with middleware. If not in traefik-v1, then maybe in traefik-v2 ...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions