HTTP内容的大小写问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/juewuer/article/details/84645670

用curl模拟http请求大家都会,对于内容也都知道,但是问几个问题
curl http://127.0.0.1/ -H “UA:Curl” -v和curl http://127.0.0.1/ -H “UA:curl” -v一样吗?
curl http://127.0.0.1/ -H “UA:Curl” -v和curl http://127.0.0.1/ -H “Ua:Curl” -v一样吗?
curl http://127.0.0.1/ -X POST -v和curl http://127.0.0.1/ -X post -v 一样吗?


可能就要犹豫了。今天正好翻了rfc,找到了答案。
RFC2616是最早的http1.0的规范,其中规定

  • Field names are case-insensitive,

现在rfc2616已经被rfc7230-7237取代,查看了这两个RFC。

rfc7230中3.1.1. Request Line中明确说明:

  • The request method is case-sensitive.
  • Recipients of an invalid request-line SHOULD respond with either a 400 (Bad Request) error or a 301 (Moved Permanently) redirect with the request-target properly encoded. A recipient SHOULD NOT attempt to autocorrect and then process the request without a redirect, since the invalid request-line might be deliberately crafted to bypass security filters along the request chain.

上面意思是说请求行里的请求方法是大小写敏感的,,收到不认识的请求方法时,应该返回400或者301重定向,而不应该修改请求方法然后继续处理。

rfc7231中4. Request Methods中说明

  • By convention, standardized methods are defined in all-uppercase US-ASCII letters.
  • All general-purpose servers MUST support the methods GET and HEAD. All other methods are OPTIONAL.

两句意思是方法应该是全大写ASCII字母,所有通用服务器必须支持GET和head.其他方法是可选的。


现在知道开始问题的答案了吧

猜你喜欢

转载自blog.csdn.net/juewuer/article/details/84645670