Chromium Code Reviews| Index: util/net/http_transport_test_server.py |
| diff --git a/util/net/http_transport_test_server.py b/util/net/http_transport_test_server.py |
| index 51d722e13299ed17d4c0eff1cfbef2f6bc3cc158..696aff9c524750725e693e4aee37df59aeb65385 100755 |
| --- a/util/net/http_transport_test_server.py |
| +++ b/util/net/http_transport_test_server.py |
| @@ -17,10 +17,13 @@ |
| """A one-shot testing webserver. |
| -When invoked, this server will write an integer to stdout, indiciating on which |
| -port the server is listening. It will then read one integer from stdin, |
| -indiciating the response code to set for a request. The server will process |
| -one HTTP request, writing it out entirely to stdout, and will then terminate. |
| +When invoked, this server will write a short integer to stdout, indiciating on |
| +which port the server is listening. It will then read one integer from stdin, |
| +indiciating the response code to be sent in response to a request. It also reads |
| +8 characters from stdin, which, after having "\r\n" appended, will form the |
| +response body in a successful response (one with code 200). The server will |
| +process one HTTP request, deliver the prearranged response to the client, and |
| +write the entire request to stdout. It will then terminate. |
| This server is written in Python since it provides a simple HTTP stack, and |
| because parsing Chunked encoding is safer and easier in a memory-safe language. |
| @@ -57,6 +60,7 @@ class BufferedReadFile(object): |
| class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
| response_code = 500 |
| + response_body = '' |
| def handle_one_request(self): |
| # Wrap the rfile in the buffering file object so that the raw header block |
| @@ -78,6 +82,9 @@ class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
| self.send_response(self.response_code) |
| self.end_headers() |
| + if self.response_code == 200: |
| + self.wfile.write(self.response_body) |
| + self.wfile.write('\r\n') |
| writer.write(body) |
| writer.flush() |
| @@ -133,8 +140,8 @@ def Main(): |
| # Read the desired test response code as an unsigned short from the parent |
| # process. |
|
scottmg
2015/02/05 23:00:39
comment out of date for "8s"
|
| - RequestHandler.response_code = \ |
| - struct.unpack('=H', sys.stdin.read(struct.calcsize('=H')))[0] |
| + RequestHandler.response_code, RequestHandler.response_body = \ |
| + struct.unpack('=H8s', sys.stdin.read(struct.calcsize('=H8s'))) |
| # Handle the request. |
| server.handle_request() |