How to inject routing info (entrypoint, router, service) into HTTP response headers?

I would like to inject some metadata into HTTP response headers in order to track who serves the request.

I already achieve this with Nginx / HA proxy, but first time I try with Traefik.

I take a look at Headers middleware but seems only to inject static info. So I take a look at creating a middleware plugin but seems to lack info about request routing (or I didn't find out how) and plugin API documentation is missing...

What do you want to inspect? Not all info is available for plugins, like the target service instance is only decided after middleware plugin stage.

We use multiple Traefik instances, inject the custom hostname, but that is done through compose, so for Traefik it’s a static value.

entrypoint, router and service names should be fine.

Sad you can't get it after call to next. It is common in filter pattern that member in the chain can inject metadata / contextual information that can be retrieve after chain call.

Ideally I would like more internal info.

Not sure if the Traefik architecture would even enable the information.

You could create a feature request on Traefik Github or even implement it yourself, create a pull to migrate changes back into main code.

1 Like