Are HTTP headers case-sensitive?

后端 未结 8 2380
梦如初夏
梦如初夏 2020-11-22 03:03

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

8条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 03:19

    tldr; both HTTP/1.1 and HTTP/2 headers are case-insensitive.

    According to RFC 7230 (HTTP/1.1):

    Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace.

    https://tools.ietf.org/html/rfc7230#section-3.2

    Also, RFC 7540 (HTTP/2):

    Just as in HTTP/1.x, header field names are strings of ASCII
    characters that are compared in a case-insensitive fashion.

    https://tools.ietf.org/html/rfc7540#section-8.1.2

提交回复
热议问题