How to Check HTTP Version

Introduction

At work I recently had a query where Python Simple HTTP Server was not working for a particular application. On the Python console "HTTP 200" responses were seeing (HTTP code for 'OK'), but the connection failed. I also tested it with 'updog - again we saw HTTP 200 responses but the connection ultimately failed.

After some investigation, it was determined that the client device required HTTP/1.1 and it was found that Python Simple HTTP Server, by default, servers HTTP/1.0. From here I wanted to understand how to determine what HTTP version is being served. It turns out that this is quite easy to do (when you know how).

How to

From the command line we can do

curl --head http://server[:port]

"[:port]" is only required if the server is not serving on the default HTTP port 80

For the Python HTTP Server, should get a result which looks like:

HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.7.3
Date: Wed, 16 Mar 2022 13:24:08 GMT
Content-type: text/html; charset=utf-8
Content-Length:1068

For an Apache server, you should see something like this:

HTTP/1.1 200 OK
Date: Web, 16 Mar 2022 13:29:49 GMT
Server: Apache/2.4.52 (Unit)
Last-Modified:  Mon, 11 Jun 2007 18:53:14 GMT
ETag: "2d-432a5e4a73a80"
Accept-Ranges: bytes
Content-Length: 45 
Content-Type: text/html

You will see from these two outputs that the first line shows which HTTP version is being served.

Conclusion

As mentioned, the Python HTTP Server will serve HTTP/1.0 by default. This can be modified, however my Python knowledge is not deep enough to understand how to modify this as yet (if I get it working, then I will make a new post). If you want to have a go at working it out yourself, then yYou can read up on the Python HTTP Server here. If you wish to run a Python HTTP Server, then you can achieve this by doing:

python -m http.server [port]

If no port number is specified, it will default to port 8000

This is great for testing how pages etc render, however it is not recommended to use this in a production environment.