diff options
author | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 22:50:55 +0000 |
---|---|---|
committer | kkimlabs@chromium.org <kkimlabs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-22 22:50:55 +0000 |
commit | 03aefffd54254d22426cf0b75d30d7590006468f (patch) | |
tree | c10d81face72127d774ce4cbf9c6bd1931a41e5d | |
parent | 5366f98ef8cd66b92a422e48a90593bdf7de966a (diff) | |
download | chromium_src-03aefffd54254d22426cf0b75d30d7590006468f.zip chromium_src-03aefffd54254d22426cf0b75d30d7590006468f.tar.gz chromium_src-03aefffd54254d22426cf0b75d30d7590006468f.tar.bz2 |
Added POST multipart echo test http server for search-by-image testing.
BUG=273877
Review URL: https://chromiumcodereview.appspot.com/23112023
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219135 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | build/android/pylib/constants.py | 1 | ||||
-rwxr-xr-x | net/tools/testserver/testserver.py | 35 |
2 files changed, 35 insertions, 1 deletions
diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py index 732c937..59ffcd42 100644 --- a/build/android/pylib/constants.py +++ b/build/android/pylib/constants.py @@ -54,6 +54,7 @@ LIGHTTPD_DEFAULT_PORT = 9000 LIGHTTPD_RANDOM_PORT_FIRST = 8001 LIGHTTPD_RANDOM_PORT_LAST = 8999 TEST_SYNC_SERVER_PORT = 9031 +TEST_SEARCH_BY_IMAGE_SERVER_PORT = 9041 # The net test server is started from port 10201. # TODO(pliard): http://crbug.com/239014. Remove this dirty workaround once diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py index 77a3142..d99c5ff 100755 --- a/net/tools/testserver/testserver.py +++ b/net/tools/testserver/testserver.py @@ -21,6 +21,7 @@ import hashlib import logging import minica import os +import json import random import re import select @@ -282,7 +283,8 @@ class TestPageHandler(testserver_base.BasePageHandler): post_handlers = [ self.EchoTitleHandler, self.EchoHandler, - self.PostOnlyFileHandler] + get_handlers + self.PostOnlyFileHandler, + self.EchoMultipartPostHandler] + get_handlers put_handlers = [ self.EchoTitleHandler, self.EchoHandler] + get_handlers @@ -662,6 +664,37 @@ class TestPageHandler(testserver_base.BasePageHandler): self.wfile.write('</body></html>') return True + def EchoMultipartPostHandler(self): + """This handler echoes received multipart post data as json format.""" + + if not (self._ShouldHandleRequest("/echomultipartpost") or + self._ShouldHandleRequest("/searchbyimage")): + return False + + content_type, parameters = cgi.parse_header( + self.headers.getheader('content-type')) + if content_type == 'multipart/form-data': + post_multipart = cgi.parse_multipart(self.rfile, parameters) + elif content_type == 'application/x-www-form-urlencoded': + raise Exception('POST by application/x-www-form-urlencoded is ' + 'not implemented.') + else: + post_multipart = {} + + # Since the data can be binary, we encode them by base64. + post_multipart_base64_encoded = {} + for field, values in post_multipart.items(): + post_multipart_base64_encoded[field] = [base64.b64encode(value) + for value in values] + + result = {'POST_multipart' : post_multipart_base64_encoded} + + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write(json.dumps(result, indent=2, sort_keys=False)) + return True + def DownloadHandler(self): """This handler sends a downloadable file with or without reporting the size (6K).""" |