How to make Firefox use HTTP/1.1

1

There is this webserver in Python (code see end of post). Whenever Firefox connects, the webserver reports HTTP/1.0.

*.*.*.* - - [17/Feb/2016 15:50:59] "GET /?size=100 HTTP/1.0" 200 -

With wget, HTTP/1.1 is used:

*.*.*.* - - [17/Feb/2016 15:16:37] "GET /?size=488 HTTP/1.1" 200 -

With netcat:

$ nc *.*.*.* 8000
GET ?size=10 HTTP/1.1

HTTP/1.1 200 OK
Server: BaseHTTP/0.3 Python/2.7.10
Date: Wed, 17 Feb 2016 14:58:48 GMT
Content-Length: 10

[content]

and

$ nc *.*.*.* 8000
GET ?size=20 HTTP/1.0

HTTP/1.1 200 OK
Server: BaseHTTP/0.3 Python/2.7.10
Date: Wed, 17 Feb 2016 14:58:59 GMT
Content-Length: 20

[content]

How can Firefox be told to use HTTP/1.1?

"""HTTP Server which generates pseudo-random traffic."""

import BaseHTTPServer
import cgi
import random
import SocketServer
import string

class ThreadingSimpleServer(SocketServer.ThreadingMixIn, 
                            BaseHTTPServer.HTTPServer):
    pass

class TrafficHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    """Server which only generates traffic."""

    def do_POST(self):
        """Does the same thing as GET."""
        try:
            self._gen_traffic(self._find_size_post())
        except (KeyError, ValueError):
            self._fail()

    def do_GET(self):
        """Generate traffic as per size parameter.

        If no size parameter is given, fail.

        """
        try:
            self._gen_traffic(self._find_size_get())
        except (IndexError, ValueError):
            self._fail()

    def _find_size_get(self):
        """Returns the value of the size parameter."""
        paramstring = self.path.split('?')[1]
        for parampair in paramstring.split('&'):
            (var, val) = parampair.split('=')
            if var == 'size':
                return int(val)
        raise IndexError('no size parameter')

    def _find_size_post(self):
        """Returns the value of the size parameter."""
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif ctype == 'application/x-www-form-urlencoded':
            length = int(self.headers.getheader('content-length'))
            postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
        else:
            raise KeyError('wrong input format: ' + ctype)
        return int(postvars['size'])

    def _fail(self):
        """Returns HTTP error message"""
        self.send_error(400, "Bad Request: could not parse the size parameter")

    # td: background thread
    def _gen_traffic(self, size):
        """Generate size bytes of traffic"""
        self.send_response(200)
        self.send_header("Content-Length", size)
        self.end_headers()
        self.wfile.write(''.join(random.choice(string.printable) 
                                 for _ in range(size)))

def test(HandlerClass = TrafficHTTPRequestHandler,
         ServerClass = ThreadingSimpleServer,
         protocol="HTTP/1.1"):
    '''starts server with default parameters'''
    import sys

    if sys.argv[1:]:
        port = int(sys.argv[1])
    else:
        port = 8000
    server_address = ('', port)

    HandlerClass.protocol_version = protocol
    httpd = ServerClass(server_address, HandlerClass)

    try:
        while 1:
            sys.stdout.flush()
            httpd.handle_request()
    except KeyboardInterrupt:
        print "Finished"

if __name__ == '__main__':
    test()

serv-inc

Posted 2016-02-17T15:03:05.570

Reputation: 400

Answers

1

If you are asking about how to change your installation of Firefox then try this... Type about:config in the address bar. Click past the "void your warranty" page if one appears. Change network.http.version to 1.1

Porcupine911

Posted 2016-02-17T15:03:05.570

Reputation: 176

If you are asking how to change your python code to force all Firefox clients to use 1.1 then I'll delete this answer. – Porcupine911 – 2016-02-17T15:55:08.593

I asked about changing the single client Firefox behavior. (Upgrading the protocol on the server side should not be possible) Yet, network.http.version is 1.1 by default. – serv-inc – 2016-02-17T15:55:29.360

1

Okay. I did find this thread at mozillazine where another person had a possibly similar issue but no solution was found.

– Porcupine911 – 2016-02-17T16:01:30.303

1

It turns out @Porcupine911's link pointed to a solution. It is reported wrongly on the server side (but only for a remote Firefox, weirdly). The solution was to use the Live HTTP Headers addon, which showed that Firefox sends a HTTP/1.1 request,

GET /?size=100 HTTP/1.1

to which the server responds with HTTP/1.1,

HTTP/1.1 200 OK

just reporting it as

"GET /?size=100 HTTP/1.0" 200 -

The error was somewhere in the network, as a Firefox on the server was reported as HTTP/1.1. This was also the cause in @Porcupine911's mozillazine.org link, where

The Mozilla debug logs show that the browser is requesting HTTP/1.1, but somewhere in between me and [the server] it's getting downgraded.

Accept to @Porcupine911, as he showed the way to a solution.

serv-inc

Posted 2016-02-17T15:03:05.570

Reputation: 400

1Glad I was able to help in a small way! – Porcupine911 – 2016-02-18T13:17:28.403