Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Unified Diff: net/tools/testserver/testserver.py

Issue 23112023: Added POST multipart echo test http server for search-by-image testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/constants.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/testserver/testserver.py
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index 77a314263001a60d083f5ed0f23e9c563cd42c76..d99c5ff72baa26ce1ec2e95e865fe30ae390a069 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)."""
« no previous file with comments | « build/android/pylib/constants.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698