Checking if a header is unset in route rule

Is there some way with nomad to check if a header is not set in a routing rule?

I think technically this should do it:

!HeadersRegexp(`x-some-header`, `.*`)

This should work because .* should always match any value, so the only time it should be false is if the header is not present.

But if I use this in conjunction with Path my Traefik web console stops working.

Exact routing rule that I'm using, which seems to break the Traefik web console, is

(!HeadersRegexp(`x-some-header`, `.*`) || HeadersRegexp(`x-some-header`, `^\d+$`)) && (PathPrefix(`/api/`) || PathPrefix(`/.well-known/oauth-authorization-server`))

If I just use this, then the web console works, but it does not match if the header is not sent:

HeadersRegexp(`x-some-header`, `^\d+$`) && (PathPrefix(`/api/`) || PathPrefix(`/.well-known/oauth-authorization-server`))

Okay, the reason the rule breaks the web-console is that there are some Traefik API endpoints that also match PathPrefix("/api/") and for some reason adding !HeadersRegexp("x-some-header", ".*") to the rule causes it to also match the Traefik API calls.

So it seems like !HeadersRegexp("x-some-header", ".*") will indeed work to detect absent headers, I just have to figure out how to prevent matching of Traefik API calls.

Okay the routing conflict was solved with priority, so this is indeed a way to check if a header is unset:

!HeadersRegexp(`x-some-header`, `.*`)
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.