fix race condition of closing http socket in web_server.py

This commit is contained in:
Arvid Norberg 2013-11-04 05:48:40 +00:00
parent 2ce6b83a8e
commit 5fcd1237f0
1 changed files with 8 additions and 4 deletions

View File

@ -25,19 +25,22 @@ class http_handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
s.send_header("Location", "/test_file")
s.send_header("Connection", "close")
s.end_headers()
s.finish()
try: s.finish()
except: pass
elif s.path == '/infinite_redirect':
s.send_response(301)
s.send_header("Location", "/infinite_redirect")
s.send_header("Connection", "close")
s.end_headers()
s.finish()
try: s.finish()
except: pass
elif s.path == '/relative/redirect':
s.send_response(301)
s.send_header("Location", "../test_file")
s.send_header("Connection", "close")
s.end_headers()
s.finish()
try: s.finish()
except: pass
elif s.path.startswith('/announce'):
s.send_response(200)
response = 'd8:intervali1800e8:completei1e10:incompletei1e5:peers0:e'
@ -45,7 +48,8 @@ class http_handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
s.send_header("Connection", "close")
s.end_headers()
s.wfile.write(response)
s.finish()
try: s.finish()
except: pass
elif os.path.split(s.path)[1].startswith('seed?'):
query = s.path[6:]
args_raw = query.split('&')