diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 02:48:15 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-11 02:48:15 +0000 |
commit | d1ec590811a1d4e593c1ba7ad52cee26cef16305 (patch) | |
tree | f79245a0252441ad145e3b41c991b3ebd7e28eb9 /net/tools | |
parent | 3431b8926e2332f47f5e5eb6f78f512ca6ba286c (diff) | |
download | chromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.zip chromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.tar.gz chromium_src-d1ec590811a1d4e593c1ba7ad52cee26cef16305.tar.bz2 |
Sanitize proxy response codes to CONNECT requests. For
anything other than 200 (success) or 400-599 (error), we
rewrite the response code as 500 (internal server error)
to prevent any special handling of the proxy's response to
CONNECT by mistake.
Add a new error code ERR_UNEXPECTED_SERVER_AUTH for a 401
response to a CONNECT request.
Fix nits reported by cpplint.py.
R=darin,eroman
BUG=7338
Review URL: http://codereview.chromium.org/21158
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r-- | net/tools/testserver/testserver.py | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py index 86b4d63..569705d 100644 --- a/net/tools/testserver/testserver.py +++ b/net/tools/testserver/testserver.py @@ -75,6 +75,9 @@ class HTTPSServer(tlslite.api.TLSSocketServerMixIn, StoppableHTTPServer): 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 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): 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 @@ class TestPageHandler(BaseHTTPServer.BaseHTTPRequestHandler): 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 @@ if __name__ == '__main__': options, args = option_parser.parse_args() sys.exit(main(options, args)) -
\ No newline at end of file + |