Index: net/tools/testserver/testserver.py |
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py |
index f9177897cc6e17b64a3fa075498365b96f0a7b81..380a217924c2234fffeb3df611a8a81dedb4f8d6 100755 |
--- a/net/tools/testserver/testserver.py |
+++ b/net/tools/testserver/testserver.py |
@@ -908,9 +908,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): |
@@ -918,11 +915,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): |
+ 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', []) |
cbentzel
2012/02/14 00:58:46
Should the expected_body argument be base64 encode
benjhayden
2012/02/14 15:52:11
If somebody has a need for it, they can add it.
|
+ if expected_body and request_body not in expected_body: |
cbentzel
2012/02/13 21:58:01
if request_body not in expected_body: should be su
benjhayden
2012/02/13 22:05:51
There are tests that do not specify expected_body,
cbentzel
2012/02/14 00:58:46
Yeah, my mistake.
You could do
expected_body
benjhayden
2012/02/14 15:52:11
It doesn't sound like there's a strong preference,
|
+ 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) |