В Python есть этот веб-сервер (код см. В конце поста). Всякий раз, когда Firefox подключается, веб-сервер сообщает 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()