Are HTTP headers case-sensitive?

后端 未结 8 2361
梦如初夏
梦如初夏 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条回答
  •  深忆病人
    2020-11-22 03:11

    HTTP header names are case-insensitive, according to RFC 2616:

    4.2:

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

    (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

    The Method token indicates the method to be performed on the
    resource identified by the Request-URI. The method is case-sensitive.

       Method         = "OPTIONS"                ; Section 9.2
                      | "GET"                    ; Section 9.3
                      | "HEAD"                   ; Section 9.4
                      | "POST"                   ; Section 9.5
                      | "PUT"                    ; Section 9.6
                      | "DELETE"                 ; Section 9.7
                      | "TRACE"                  ; Section 9.8
                      | "CONNECT"                ; Section 9.9
                      | extension-method
       extension-method = token
    

提交回复
热议问题