这里有 Python 中的 Web 服务器(代码见文章末尾)。每当 Firefox 连接时,Web 服务器都会报告 HTTP/1.0。
*.*.*.* - - [17/Feb/2016 15:50:59] "GET /?size=100 HTTP/1.0" 200 -
使用wget
HTTP/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
如果你问如何改变您的安装的 Firefox,然后尝试此操作...about:config
在地址栏中输入。如果出现“使保修失效”页面,请单击该页面。更改network.http.version
为1.1
答案2
事实证明@Porcupine911 的链接指出了一个解决方案。服务器端会错误地报告该问题(但奇怪的是,只针对远程 Firefox)。解决方案是使用Live HTTP Headers 插件,显示 Firefox 发送了 HTTP/1.1 请求,
GET /?size=100 HTTP/1.1
服务器以 HTTP/1.1 进行响应,
HTTP/1.1 200 OK
只是报告它
"GET /?size=100 HTTP/1.0" 200 -
这错误发生在网络某处,因为服务器上的 Firefox 被报告为 HTTP/1.1。这也是@Porcupine911 的 mozillazine.org 链接, 在哪里
Mozilla 调试日志显示浏览器正在请求 HTTP/1.1,但在我和 [服务器] 之间的某个地方,它正在降级。
接受@Porcupine911,因为他指明了解决问题的方法。