Search code examples
regexpcrehaproxyresponse-headers

haproxy http-response replace


I am trying to replace this part of the string in the response header "abc,def,ghi,jkl" . Please note this value is NOT static.

  My-Customer-Header: My-Test:abc,def,ghi,jkl:12345 

Using this regex I am able to grab strings between the colon. i.e. "My-Test" & "12345" https://regex101.com/r/Ebkzjb/1

Here is what i am trying to replace value..

  My-Test:XYZ:12345

Here is my haproxy config line..

  http-response replace-value  My-Customer-Header (.*)((?<=:)(.*)(?=:))(.*) \1XYZ\2

Syntactically, haproxy config is loading but i may not have the regex properly. Can you please help with haproxy config for replace the value.


Solution

  • This is working for me

     http-response replace-header My-Customer-Header (.*)((?<=:)(.*)(?=:))(.*) \1XYZ\4