Support Python scripts in test/www/.
Rather than add all the special URLs we'll ever want to run-tests.py,
the embedded HTTP server now supports scripts in test/www/. If you
try to load http://localhost:9180/path and test/www/path doesn't exist
but test/www/path.py does, then test/www/path.py is loaded as a module.
That module must export one function, handle_request(), which is called
to produce the response.
handle_request() has the same semantics as
SimpleHTTPRequestHandler.send_head(). That is, it takes one argument,
the SimpleHTTPRequestHandler object, conventionally named 'req'.
It should call the send_response(), send_header(), and end_headers()
methods of that object as appropriate. And it should return a readable
filelike whose contents are taken as the body of the response.
If either module import or handle_request() throws any exception, the
HTTP response will be a 500 Internal Server Error with body provided
by cgitb.
Ongoing work on issue #12439.
2014-09-12 23:43:29 +04:00
|
|
|
import cStringIO as StringIO
|
|
|
|
import urlparse
|
|
|
|
|
|
|
|
def handle_request(req):
|
|
|
|
url = urlparse.urlparse(req.path)
|
|
|
|
|
|
|
|
body = "<!doctype html><h1>Status: {}</h1>".format(url.query)
|
|
|
|
|
2014-09-16 08:38:36 +04:00
|
|
|
req.send_response(int(url.query))
|
|
|
|
req.send_header('Content-Type', 'text/html')
|
|
|
|
req.send_header('Content-Length', str(len(body)))
|
|
|
|
req.end_headers()
|
2014-09-17 00:56:27 +04:00
|
|
|
return StringIO.StringIO(body)
|