Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get nginx to add a header without converting it to lowercase?

Tags:

nginx

In my nginx config, I have the line

add_header 'X-Custom-Header' 'example' always;

When I access the page with curl -I http://<path to page> it returns the header as x-custom-header rather than X-Custom-Header as typed.

While HTTP headers are case-insensitive, and so this is still valid, I take the view that I am perfectly capable of typing a header in lowercase if that's what I want; I would rather have nginx do what it's told rather than something vaguely along the lines of what I told it to do.

Is there a way to stop it downcasing headers?

like image 363
John Y Avatar asked Oct 29 '25 10:10

John Y


1 Answers

Looks like you are accessing your site using HTTP/2 protocol. This is exactly the expected behavior when request is served using HTTP/2, as RFC 7540 states:

Just as in HTTP/1.x, header field names are strings of ASCII characters that are compared in a case-insensitive fashion. However, header field names MUST be converted to lowercase prior to their encoding in HTTP/2. A request or response containing uppercase header field names MUST be treated as malformed.

like image 78
Ivan Shatsky Avatar answered Nov 01 '25 12:11

Ivan Shatsky