Search code examples
pythonbasehttpserver

Http version in response BaseHttp module python


I am running a server with BaseHttp with python.

I receive a request from a client which is based on HTTP/ 1.1

However, when I am answering the client back with my response, the client refuses to accept my response. On further analysis I saw that the HTTP Version I am sending is HTTP/1.0. However , I dont know how is it set.

The error at the client side is.

Original message: not well-formed (invalid token): line 2, column 4 
Response 
HTTP/1.0 200 OK
Server: BaseHTTP/0.3 Python/2.7.5
Date: Wed, 30 Jul 2014 15:11:42 GMT
Content-type: application/soap+xml; charset=utf-8
Content-length: 823

I am setting the header in the following way:

self.send_response(200)
self.send_header("Content-type", "application/soap+xml; charset=utf-8")
self.send_header("Content-length", content_length)
self.end_headers()

Solution

  • Set the protocol_version attribute on your handler class:

    handler.protocol_version = 'HTTP/1.1'
    

    This requires that you set a Content-Length header, which you already do.