Daniel Krom
Daniel Krom

Reputation: 10068

HAProxy add header based on URL parameter

Using HAProxy v1.6

I'm doing Websocket request that currently (at least on javascript) won't support custom headers.

I'm trying to add a custom header at the HAProxy layer (before forwarding it to the load balancer) based on a get parameter

Example:

The next code works (on backend)

#match get-url someGetKey paramater
acl is_key_match        url_reg          \?(?:.*?)someGetKey=([\w|=]+)
#Add header
http-request set-header My-Custom-Header hardcoded_string if is_key_match

My goal is the to replace hardcoded_string with the first match group of the regex \?(?:.*?)someGetKey=([\w|=]+)

Is it possible?

Thanks!

Upvotes: 1

Views: 3037

Answers (1)

Daniel Krom
Daniel Krom

Reputation: 10068

Found the solution:

http-request set-header cookie %[urlp(SSession)] if is_sticky_url

%[] - variable
url(SSession) - HTTP-GET parameter with the key SSession

For that example, the URL:

https://www.example.com/path?sSession=abcd

will forward a request with the header:

cookie=abcd

Upvotes: 1

Related Questions