Index: net/tools/testserver/testserver.py |
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py |
index 12882b5dcd9cf6dca05a1e0d4516a518d84067da..f280333473a327c6046e966279cc7207218c6b0f 100755 |
--- a/net/tools/testserver/testserver.py |
+++ b/net/tools/testserver/testserver.py |
@@ -909,9 +909,6 @@ class TestPageHandler(BasePageHandler): |
prefix = self.server.file_root_url |
if not self.path.startswith(prefix): |
return False |
- # Consume a request body if present. |
- if self.command == 'POST' or self.command == 'PUT' : |
- self.ReadRequestBody() |
return self._FileHandlerHelper(prefix) |
def PostOnlyFileHandler(self): |
@@ -919,12 +916,33 @@ class TestPageHandler(BasePageHandler): |
prefix = urlparse.urljoin(self.server.file_root_url, 'post/') |
if not self.path.startswith(prefix): |
return False |
- self.ReadRequestBody() |
return self._FileHandlerHelper(prefix) |
def _FileHandlerHelper(self, prefix): |
- old_protocol_version = self.protocol_version |
+ request_body = '' |
+ if self.command == 'POST' or self.command == 'PUT': |
+ # Consume a request body if present. |
+ request_body = self.ReadRequestBody() |
+ |
_, _, url_path, _, query, _ = urlparse.urlparse(self.path) |
+ query_dict = cgi.parse_qs(query) |
+ |
+ expected_body = query_dict.get('expected_body', []) |
+ if expected_body and request_body not in expected_body: |
+ self.send_response(404) |
+ self.end_headers() |
+ self.wfile.write('') |
+ return True |
+ |
+ expected_headers = query_dict.get('expected_headers', []) |
+ for expected_header in expected_headers: |
+ header_name, expected_value = expected_header.split(':') |
+ if self.headers.getheader(header_name) != expected_value: |
+ self.send_response(404) |
+ self.end_headers() |
+ self.wfile.write('') |
+ return True |
+ |
sub_path = url_path[len(prefix):] |
entries = sub_path.split('/') |
file_path = os.path.join(self.server.data_dir, *entries) |
@@ -942,6 +960,8 @@ class TestPageHandler(BasePageHandler): |
data = self._ReplaceFileData(data, query) |
+ old_protocol_version = self.protocol_version |
+ |
# If file.mock-http-headers exists, it contains the headers we |
# should send. Read them in and parse them. |
headers_path = file_path + '.mock-http-headers' |