Hello list, I need to add a Vary header with Origin value in order to properly 
configure a Cors Allow Origin with dynamic content. This works well provided 
that my backend doesn’t need to configure another value to the Vary header. I 
observed that if I configure set-header, this will overwrite the header 
provided by the app; if I configure add-header, this will create another header 
instead of concatenate the values into a single one, as suggested here[1] and 
here[2].

At this moment these are the best configurations that I managed to build:

A)
  http-response set-header vary %[res.hdr(vary)],origin if { res.hdr(vary) -m 
found }
  http-response set-header vary origin if ! { res.hdr(vary) -m found }

B)
  http-response replace-header vary (.*) \1,origin if { res.hdr(vary) -m found }
  http-response set-header vary origin if ! { res.hdr(vary) -m found }

Option A would remove some previous duplicated vary header, preserving just one 
of them; option B would add origin on all duplicated headers. And all of them 
seems to be more verbose than needed.

It seems that I’m missing some haproxy config here. Is there a better or 
suggested way to add a new value to an existing header without adding a new 
whole header line?

~jm

[1] https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary


Reply via email to