Files
Zack Weinberg 3d4f89b41e Bug fixes to test-server Python response hook support.
* correctly fake a package to hold all the response-hook modules
* use StringIO correctly in the response hooks
* prevent .py(c) files in test/www/ from being accessed directly
* prevent test/www/__init__ from being treated as a response hook
* add a test case that makes sure the existing hooks _can_ return 200 OK

(issue #12439; buggy commit 4d60e94)
2014-09-16 20:56:27 +00:00

29 lines
770 B
Python

import json
import urlparse
import cStringIO as StringIO
def handle_request(req):
url = urlparse.urlparse(req.path)
headers = {}
for name, value in req.headers.items():
headers[name] = value.rstrip()
d = dict(
command = req.command,
version = req.protocol_version,
origin = req.client_address,
url = req.path,
path = url.path,
params = url.params,
query = url.query,
fragment = url.fragment,
headers = headers
)
body = json.dumps(d, indent=2) + '\n'
req.send_response(200)
req.send_header('Content-Type', 'application/json')
req.send_header('Content-Length', str(len(body)))
req.end_headers()
return StringIO.StringIO(body)