Search code examples
haproxy

How to use set-header with a variable concatenated with req.hdr()


I am using set-header to rename an incoming header from an existing one. My problem is that in addition to renaming the header using req.hdr(my-old-header-name) I want to concatenate the interpreted value from the req.hdr() function with another static value (Bearer).

http-request set-header Authorization %[req.hdr(my-old-header-name)] if some-condition-applies

I want to be able to add a value "Bearer " in front of the interpreted %[req.hdr(my-old-header-name)] so that it ends up looking like this: Authorization: Bearer my-old-header-value-interpreted-from-req-hdr

Thanks for helping


Solution

  • Managed to make it work with replace-header as following:

    http-request replace-header Authorization (.*) Bearer\ \1 if some_condition_applies

    This basically takes the value of the Authorization header and prefixes it with Bearer.