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

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

Issue 21158: Fix a logic error in the handling the response to an HTTP... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | « net/http/http_response_headers.h ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/testserver/testserver.py
===================================================================
--- net/tools/testserver/testserver.py (revision 9548)
+++ net/tools/testserver/testserver.py (working copy)
@@ -75,6 +75,9 @@
class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def __init__(self, request, client_address, socket_server):
+ self._connect_handlers = [
+ self.RedirectConnectHandler,
+ self.DefaultConnectResponseHandler]
self._get_handlers = [
self.KillHandler,
self.NoCacheMaxAgeTimeHandler,
@@ -854,7 +857,7 @@
self.wfile.write('<html><head>')
self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest)
- return True;
+ return True
def ClientRedirectHandler(self):
"""Sends a client redirect to the given URL. The syntax is
@@ -893,6 +896,41 @@
self.wfile.write(contents)
return True
+ def RedirectConnectHandler(self):
+ """Sends a redirect to the CONNECT request for www.redirect.com. This
+ response is not specified by the RFC, so the browser should not follow
+ the redirect."""
+
+ if (self.path.find("www.redirect.com") < 0):
+ return False
+
+ dest = "http://www.destination.com/foo.js"
+
+ self.send_response(302) # moved temporarily
+ self.send_header('Location', dest)
+ self.send_header('Connection', 'close')
+ self.end_headers()
+ return True
+
+
+ def DefaultConnectResponseHandler(self):
+ """This is the catch-all response handler for CONNECT requests that aren't
+ handled by one of the special handlers above. Real Web servers respond
+ with 400 to CONNECT requests."""
+
+ contents = "Your client has issued a malformed or illegal request."
+ self.send_response(400) # bad request
+ self.send_header('Content-type', 'text/html')
+ self.send_header("Content-Length", len(contents))
+ self.end_headers()
+ self.wfile.write(contents)
+ return True
+
+ def do_CONNECT(self):
+ for handler in self._connect_handlers:
+ if handler():
+ return
+
def do_GET(self):
for handler in self._get_handlers:
if handler():
@@ -1015,4 +1053,4 @@
options, args = option_parser.parse_args()
sys.exit(main(options, args))
-
+
« no previous file with comments | « net/http/http_response_headers.h ('k') | net/url_request/url_request_http_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698