1

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

Dmitry Petukhov
  • 586
  • 2
  • 12
  • 26
  • I've not used anything like this before in Python so I might be completely out of the ball park but from a Google search I found something that might explain it: [BaseHTTPRequestHandler.protocol_version](https://docs.python.org/3/library/http.server.html#http.server.BaseHTTPRequestHandler.protocol_version): "This specifies the HTTP protocol version used in responses." Perhaps there's a `protocol_version` property you can set for `SimpleHTTPServer` before you launch it. – Tagc Aug 07 '16 at 10:18

2 Answers2

2

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

cuongnv23
  • 382
  • 2
  • 7
1

It's just a version number, the server supports the older 1.0 protocol.

See HTTP 1.0 vs 1.1

Community
  • 1
  • 1
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176