Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am testing using nginx/php5-fpm, with the code

<?php

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

echo $_SERVER["SERVER_PROTOCOL"];

And force to use HTTP 1.0 with the curl command.

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

As you can see I am already requesting using HTTP 1.0, but nginx reply me with HTTP 1.1

Bounty

@MaximDounin, @MichaelHampton already provided an answer to the spec, thanks. I am extending this question a little bit for the future reader:

Q. What are the advantage of responding HTTP 1.1 when a client request for HTTP 1.0? Shouldn't the approach taken by Google more reasonable, i.e. when client request 1.0, response with 1.0?

share|improve this question

2 Answers 2

up vote 17 down vote accepted

This is normal and expected behavior, 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.

What this means in English is: If the client sends an HTTP/1.0 request, either an HTTP/1.0 response or HTTP/1.1 is acceptable, but HTTP/1.1 is preferred.

The reason this is done is so that one end may advertise the highest version of HTTP that it can support, so that the other end may choose to upgrade its protocol support (if possible). Both ends will then decide what protocol version they can both live with. This design also helps to deal with buggy implementations, as RFC 2145 stated.

It was also envisioned at the time that there may be further versions of the HTTP protocol, both minor and major versions, and the rules were meant to help ensure interoperability. Google's RFC-ignorant approach may break once HTTP/2.0 is finalized. (You know it in its draft form as SPDY.)

share|improve this answer
    
You can try this: curl -0 -v 'http://www.google.com/foo', curl -v 'http://www.google.com/foo', they response 1.0 or 1.1 version of 404 correctly but not in my case. –  Ryan Oct 28 '12 at 2:55
    
Google runs a custom web server and does whatever they want to do. So what? –  Michael Hampton Oct 28 '12 at 2:56
5  
No, nginx will never downgrade response version to 1.0. On the other hand, it won't use protocol features not available in HTTP/1.0. E.g. it won't try to keep connection alive, and won't use chunked transfer-coding. –  Maxim Dounin Oct 28 '12 at 19:06
1  
@MaximDounin, do you mean when nginx know client does not support 1.1, it will still send respond as 1.1, but without the actual 1.1 feature? Wouldn't it be confusing? –  Ryan Oct 30 '12 at 4:37
5  
It is in-line with RFC 2145, and allows clients to find out HTTP version supported by a server without additional requests. You may want to re-read RFC 2145 if you still find it confusing. –  Maxim Dounin Oct 30 '12 at 14:01

Q. What are the advantage of responding HTTP 1.1 when a client request for HTTP 1.0?

It's actually sending you an HTTP/1.0-compliant response. It will not use any features such as keepalive that require HTTP/1.1.

The reason for doing this is because it's a cheap way for the server to say:

"hey, I know you sent me a request using HTTP/1.0, but just to let you know I AM capable of HTTP/1.1. and here's the response to your original request: [..]"

(Note: If the server supported a fictional HTTP/1.8, it would respond with that.)

This saves you an additional request in some situations. If you need to GET 3 different URIs from a server, you could send the first one as HTTP/1.0, then move up to the highest version that both you and the server support for the subsequent requests.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.