php – Nginx忽略客户端的HTTP 1.0请求并通过HTTP 1.1响应

前端之家收集整理的这篇文章主要介绍了php – Nginx忽略客户端的HTTP 1.0请求并通过HTTP 1.1响应前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用Nginx / PHP5-fpm测试代码
<?PHP

header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); 
// also tested: header("Status: 404 Not Found");

echo $_SERVER["SERVER_PROTOCOL"];

并强制使用带有curl命令的HTTP 1.0.

curl -0 -v 'http://www.example.com/test.PHP'


> GET /test.PHP HTTP/1.0

< HTTP/1.1 404 Not Found
< Server: Nginx
< Date: Sat,27 Oct 2012 08:51:27 GMT
< Content-Type: text/html
< Connection: close
< 
* Closing connection #0
HTTP/1.0

正如您所看到的,我已经在请求使用HTTP 1.0,但是Nginx用HTTP 1.1回复了我

赏金

@MaximDounin,@ MichaelHampton已经提供了规范的答案,谢谢.我正在为未来的读者扩展这个问题:

问:当客户端请求HTTP 1.0时,响应HTTP 1.1有什么好处?谷歌采取的方法不应该更合理,即当客户请求1.0时,响应为1.0?

这是正常和预期的行为,according to RFC 2616

Applications that are at least conditionally compliant with this specification SHOULD use an HTTP-Version of “HTTP/1.1” in their messages,and MUST do so for any message that is not compatible with HTTP/1.0. For more details on when to send specific HTTP-Version values,see RFC 2145.

RFC 2145 expands on this

An HTTP server SHOULD send a response version equal to the highest version for which the server is at least conditionally compliant,and whose major version is less than or equal to the one received in the request. An HTTP server MUST NOT send a version for which it is not at least conditionally compliant. A server MAY send a 505 (HTTP Version Not Supported) response if cannot send a response using the major version used in the client’s request.

An HTTP server MAY send a lower response version,if it is known or suspected that the client incorrectly implements the HTTP specification,but this should not be the default,and this SHOULD NOT be done if the request version is HTTP/1.1 or greater.

这意味着英语是:如果客户端发送HTTP / 1.0请求,则可以接受HTTP / 1.0响应或HTTP / 1.1,但首选HTTP / 1.1.

这样做的原因是一端可以通告它可以支持的最高版本的HTTP,以便另一端可以选择升级其协议支持(如果可能的话).然后,两端将决定他们可以使用的协议版本.正如RFC 2145所述,这种设计也有助于处理错误的实现.

当时还设想可能存在HTTP协议的其他版本,包括次要版本和主要版本,并且规则旨在帮助确保互操作性.一旦HTTP/2.0最终确定,谷歌的RFC无知方法可能会破裂. (你知道它的草稿形式是SPDY.)

原文链接:https://www.f2er.com/php/139424.html

猜你在找的PHP相关文章