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?
Header names are not case sensitive.
From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers":
The updating RFC 7230 does not list any changes from RFC 2616 at this part.
header('Content-type: image/png')
did not work with PHP 5.5 serving IE11, as in the image stream was shown as textheader('Content-Type: image/png')
worked, as in the image appeared as an imageOnly difference is the capital 'T'.
tldr; both HTTP/1.1 and HTTP/2 headers are case-insensitive.
According to RFC 7230 (HTTP/1.1):
https://tools.ietf.org/html/rfc7230#section-3.2
Also, RFC 7540 (HTTP/2):
https://tools.ietf.org/html/rfc7540#section-8.1.2
The RFC for HTTP (as cited above) dictates that the headers are case-insensitive, however you will find that with certain browsers (I'm looking at you, IE) that capitalizing each of the words tends to be best:
vs
This isn't "HTTP" standard, but just another one of the browser quirks, we as developers, have to think about.
HTTP header names are case-insensitive, according to RFC 2616:
4.2:
(Field values may or may not be case-sensitive.)
If you trust the major browsers to abide by this, you're all set.
BTW, unlike most of HTTP, methods (verbs) are case sensitive:
5.1.1 Method