We have an API backend server that requires certain HTTP headers which contain underscores. I know that this is not best practice and headers should use hyphens but I cannot change this.
We were using nginx as a proxy server with the option underscores_in_headers on
. That causes nginx to not drop these headers.
Now we want to switch to HAProxy and as nginx before the configuration change it drops headers with underscores. Is there a way to prevent HAProxy from dropping headers with underscores?
Best Answer
Have you actually tested that HAProxy drops headers with underscores?
From the source code it seems like it doesn't. In this answer I'll try to explain:
HTTP/1.1 & Nginx
According to the HTTP/1.1 specification in RFC 7230 3.2.6, there's nothing wrong with underscores (
_
) in header fields; it's only uncommon.Nginx Pitfalls and Common Mistakes: Missing (disappearing) HTTP Headers explains why they are still silently dropped by default:
HAProxy
Unfortunately, HAProxy does not have such a setting. If you search
underscore
through the HAProxy Configuration Manual, it's only mentioned in the contexts of environment variables, node names (like in DNS names), proxy names and ACL names. Not mentioned in HTTP request chapter.If HAProxy does drop the headers with underscores, there's nothing you can do from the configuration and you would have to either stick to the Nginx or modify HAProxy's source code.
However, I tried to find where HAProxy drops there headers and couldn't find such a thing from
proto_http.c
's functionsvoid capture_headers()
andvoid http_msg_analyzer()
.Also,
proto_http.c
lists all ASCII characters by type, and(),/:;<=>?@[\]{}
are listed asHTTP_FLG_SEP
while underscore is listed as a normal token:Here,
_
is just a normalHTTP_FLG_TOK
just likeA
,B
andC
; it shouldn't cause anything special.