Dmitry Petukhov Dmitry Petukhov - 3 months ago 9
HTTP Question

Why cURL response from server is HTTP/1.0?

I had created simple server in terminal

python -m SimpleHTTPServer 8000


when I send command
curl -I http://localhost:8000


and command result was a request:

127.0.0.1 - - [07/Aug/2016 14:53:22] "GET / HTTP/1.1" 200 -


but response was a
HTTP/1.0


HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/2.7.12
Date: Sun, 07 Aug 2016 10:02:08 GMT
Content-type: text/html; charset=utf-8
Content-Length: 9747


curl -v http://localhost:8000


* Rebuilt URL to: http://localhost:8000/
* Trying ::1...
* connect to ::1 port 8000 failed: Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.43.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: SimpleHTTP/0.6 Python/2.7.12
< Date: Sun, 07 Aug 2016 10:02:23 GMT
< Content-type: text/html; charset=utf-8
< Content-Length: 9747
<
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html>
...
</html>
* Closing connection 0


How we can explain this? Why server response was not a
HTTP/1.1

Answer

curl uses HTTP/1.1 by default from version 7.33.0 (yours is 7.43.0). In man curl:

--http1.1
              (HTTP) Tells curl to use HTTP version 1.1. This is the internal default version. (Added in 7.33.0)

So curl will make a request with HTTP/1.1 to your server.

This line 127.0.0.1 - - [07/Aug/2016 14:53:22] "GET / HTTP/1.1" 200 -

is just a log entry which tells you that there is a request made with expected to get HTTP/1.1 BUT it doesn't mean server must response with HTTP/1.1, see the link of Karoly Horvath for detail.

Looking at source code of SimpleHTTPServer, you can see there is a default request version which is HTTP/0.9.

This default_request_version variable is then assigned to self.request_version in line 244.

The function which does the response is send_response and at line 402 there is a comparison with HTTP/0.9, this leads to the protocol version is protocol_version is HTTP/1.0 in line 515

Comments