Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 header - HTTP 1.0 or 1.1?

Why does almost every example I can find (including this question from about a year ago) say that a 404 header should be HTTP/1.0 404 Not Found when we've really been using HTTP 1.1 for over a decade? Is there any reason not to send HTTP/1.1 404 Not Found instead?

(Not that it matters all that much... I'm mostly just curious.)

like image 261
keithjgrant Avatar asked May 04 '10 22:05

keithjgrant


People also ask

Is HTTP 1.0 still used?

A small number of mobile applications still use HTTP 1.0. This early version of the HTTP protocol doesn't support improvements, like persistent TCP connections, that make HTTP 1.1 much more efficient to use.

Is HTTP 1.1 backward compatibility?

This specification defines the protocol referred to as "HTTP/1.1". This protocol is backwards-compatible with HTTP/1.0, but includes more stringent requirements in order to ensure reliable implementation of its features.

Which version of HTTP is currently use in network?

HTTP/1.1 — The standardized protocol This is the HTTP version currently in common use.


4 Answers

In PHP you should probably use:

header( $_SERVER['SERVER_PROTOCOL']." 404 Not Found", true ); 

or even better

header( $_ENV['SERVER_PROTOCOL']." 404 Not Found", true ); 

(if supported) and thus leave it to the web-server which protocol to use.

Actually, if you pass the status code as 3rd parameter, you can pass whatever you want in the 1st one, as long as it's not empty, and PHP will do the rest. See http://php.net/header

header("foobar", true, 404 ); 

Also: You can't request a certain protocol version from the client-side since the transaction is hop-to-hop based, and not end-to-end. The server and your browser may very well use HTTP/1.1, but if a proxy inbetween is using only HTTP/1.0, that's what you will see from your client.

like image 195
DanMan Avatar answered Sep 22 '22 13:09

DanMan


The usage of HTTP version can be based on the following factors:

  • Your web server support for HTTP 1.0 or 1.1
  • The web browser's support for HTTP 1.0 or 1.1
  • Your preference as a web developer on which protocol version to use

Modern browsers can support both 1.0 and 1.1 well, and both the client and server will settle for the highest version both can support together. The key differences between the 2 protocol can be found: http://www8.org/w8-papers/5c-protocols/key/key.html

However there's no key differences in the usage of 404 Not Found. However do be consistent for your whole website. i.e. if you use HTTP/1.1, you use it throughout your website.

like image 26
mauris Avatar answered Sep 23 '22 13:09

mauris


It does not matter all that much. The client is responsible for telling the server which version of HTTP it uses. Then, the server is supposed to answer with the same version. This does not always happen; I just got this response from a server:

$ telnet example.com 80
Trying 123.123.123.123...
Connected to example.com.
Escape character is '^]'.
GET /fork HTTP/1.0

HTTP/1.1 404 Not Found
Content-Length: 1635
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Tue, 04 May 2010 22:30:36 GMT
Connection: close

I asked the server to use HTTP 1.0, but it went ahead and responded with HTTP 1.1.

like image 35
Kevin Panko Avatar answered Sep 25 '22 13:09

Kevin Panko


I'd have thought that the response should be HTTP/1.0 404 Not Found if the request was a HTTP 1.0, and HTTP/1.1 404 Not Found if the request was HTTP 1.1.

In practice, it's going to be easier for servers to returned canned responses, and the HTTP 1.0 response will be understood by both 1.0 and 1.1 clients, so safest to return that. If you know the client understands 1.1 (e.g. because that's what it asked for), then the 1.1 response should work.

Arguably, play it safe and send the 1.0 response.

like image 35
skaffman Avatar answered Sep 21 '22 13:09

skaffman