08 February 2014

一句话:HTTP协议的Method是大小写敏感的,其他Header的key是大小写不敏感的。当然消息内容是区分大小写的。

关心这个问题,是因为今天在用程序模拟用户登陆时,读取response的header时,用Set-Cookie作为key时,返回为空,必须用小写的set-cookie才能读到结果。

w3c看标准,结果如下:

HTTP header fields, which include general-header (section 4.5),
request-header (section 5.3), response-header (section 6.2), and
entity-header (section 7.1) fields, follow the same generic format as
that given in Section 3.1 of RFC 822 [9]. Each header field consists
of a name followed by a colon (":") and the field value. Field names
are case-insensitive.

协议中说了,header的name是大小写不区分的。搜索协议文档,有四个出处是case-sensitive的,其中有两个是URI和方法名Method Name,这两个是区分大小写的:

3.2.3 URI Comparison

   When comparing two URIs to decide if they match or not, a client
   SHOULD use a case-sensitive octet-by-octet comparison of the entire
   URIs, with these exceptions:
       - A port that is empty or not given is equivalent to the default
         port for that URI-reference;
       - Comparisons of host names MUST be case-insensitive;
       - Comparisons of scheme names MUST be case-insensitive;
       - An empty abs_path is equivalent to an abs_path of "/".
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

协议只说了区分还是不区分大小写,但没说怎么实现不区分大小写,也就是说,怎么处理大小写问题,是都转成大写,还是都转成小写,是在发送时进行转换,还是在接受时进行转换。如果应用程序发送两个仅仅是大小写不同的header,用户代理如何处理?web Server又该如何处理?web server端的应用程序呢?,于是用代码验证。

-----------------分割线------------------ 未完待续。。。



blog comments powered by Disqus