Monday, 15 May 2017

Are HTTP headers case-sensitive?



In a blog post I use the following PHP to set the content-type of a response:



header('content-type: application/json; charset=utf-8');



I just got a comment on that post saying that content-type needs to be capitalized, Content-type. Is this correct? It seems to work for me with all lower-case, and I assumed the HTTP headers were case-insensitive. Or does it just work because browsers are nice?


Answer



Header names are not case sensitive.



From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers":




Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.





The updating RFC 7230 does not list any changes from RFC 2616 at this part.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...