Как заставить Firefox использовать HTTP / 1.1

3250
serv-inc

В Python есть этот веб-сервер (код см. В конце поста). Всякий раз, когда Firefox подключается, веб-сервер сообщает HTTP / 1.0.

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

С wgetHTTP / 1.1 используется:

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

С 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] 

а также

$ 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] 

Как Firefox можно сказать использовать 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() 
1

2 ответа на вопрос

1
Porcupine911

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

Если вы спрашиваете, как изменить код Python, чтобы заставить всех клиентов Firefox использовать 1.1, я удалю этот ответ. Porcupine911 8 лет назад 0
Я спросил об изменении поведения одиночного клиента Firefox. (Обновление протокола на стороне сервера не должно быть возможным). Тем не менее, `network.http.version` по умолчанию равен 1.1. serv-inc 8 лет назад 0
Хорошо. Я нашел [эту ветку в mozillazine] (http://forums.mozillazine.org/viewtopic.php?f=38&t=2902619), где у другого человека была похожая проблема, но решение не было найдено. Porcupine911 8 лет назад 1
1
serv-inc

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.

Рад, что смог немного помочь! Porcupine911 8 лет назад 1