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

Side by Side Diff: net/tools/testserver/testserver.py

Issue 612533002: Add /cross-site/ request handler to testserver.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for 6 """This is a simple HTTP/FTP/TCP/UDP/BASIC_AUTH_PROXY/WEBSOCKET server used for
7 testing Chrome. 7 testing Chrome.
8 8
9 It supports several test URLs, as specified by the handlers in TestPageHandler. 9 It supports several test URLs, as specified by the handlers in TestPageHandler.
10 By default, it listens on an ephemeral port and sends the port number back to 10 By default, it listens on an ephemeral port and sends the port number back to
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 self.SetManyCookiesHandler, 324 self.SetManyCookiesHandler,
325 self.ExpectAndSetCookieHandler, 325 self.ExpectAndSetCookieHandler,
326 self.SetHeaderHandler, 326 self.SetHeaderHandler,
327 self.AuthBasicHandler, 327 self.AuthBasicHandler,
328 self.AuthDigestHandler, 328 self.AuthDigestHandler,
329 self.SlowServerHandler, 329 self.SlowServerHandler,
330 self.ChunkedServerHandler, 330 self.ChunkedServerHandler,
331 self.ContentTypeHandler, 331 self.ContentTypeHandler,
332 self.NoContentHandler, 332 self.NoContentHandler,
333 self.ServerRedirectHandler, 333 self.ServerRedirectHandler,
334 self.CrossSiteRedirectHandler,
334 self.ClientRedirectHandler, 335 self.ClientRedirectHandler,
335 self.GetSSLSessionCacheHandler, 336 self.GetSSLSessionCacheHandler,
336 self.SSLManySmallRecords, 337 self.SSLManySmallRecords,
337 self.GetChannelID, 338 self.GetChannelID,
338 self.ClientCipherListHandler, 339 self.ClientCipherListHandler,
339 self.CloseSocketHandler, 340 self.CloseSocketHandler,
340 self.RangeResetHandler, 341 self.RangeResetHandler,
341 self.DefaultResponseHandler] 342 self.DefaultResponseHandler]
342 post_handlers = [ 343 post_handlers = [
343 self.EchoTitleHandler, 344 self.EchoTitleHandler,
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 1412
1412 self.send_response(301) # moved permanently 1413 self.send_response(301) # moved permanently
1413 self.send_header('Location', dest) 1414 self.send_header('Location', dest)
1414 self.send_header('Content-Type', 'text/html') 1415 self.send_header('Content-Type', 'text/html')
1415 self.end_headers() 1416 self.end_headers()
1416 self.wfile.write('<html><head>') 1417 self.wfile.write('<html><head>')
1417 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) 1418 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest)
1418 1419
1419 return True 1420 return True
1420 1421
1422 def CrossSiteRedirectHandler(self):
1423 """Sends a server redirect to the given site. The syntax is
1424 '/cross-site/hostname/...' to redirect to //hostname/...
1425 It is used to navigate between different Sites, causing
1426 cross-site/cross-process navigations in the browser."""
1427
1428 test_name = "/cross-site"
1429 if not self._ShouldHandleRequest(test_name):
1430 print "CSRH: not handling request for " + test_name
1431 return False
1432
1433 params = urllib.unquote(self.path[(len(test_name) + 1):])
1434 slash = params.find('/')
1435 if slash < 0:
1436 self.sendRedirectHelp(test_name)
1437 return True
1438
1439 host = params[:slash]
1440 path = params[(slash+1):]
1441 dest = "//%s:%s/%s" % (host, str(self.server.server_port), path)
1442
1443 self.send_response(301) # moved permanently
1444 self.send_header('Location', dest)
1445 self.send_header('Content-Type', 'text/html')
1446 self.end_headers()
1447 self.wfile.write('<html><head>')
1448 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest)
1449
1450 return True
1451
1421 def ClientRedirectHandler(self): 1452 def ClientRedirectHandler(self):
1422 """Sends a client redirect to the given URL. The syntax is 1453 """Sends a client redirect to the given URL. The syntax is
1423 '/client-redirect?http://foo.bar/asdf' to redirect to 1454 '/client-redirect?http://foo.bar/asdf' to redirect to
1424 'http://foo.bar/asdf'""" 1455 'http://foo.bar/asdf'"""
1425 1456
1426 test_name = "/client-redirect" 1457 test_name = "/client-redirect"
1427 if not self._ShouldHandleRequest(test_name): 1458 if not self._ShouldHandleRequest(test_name):
1428 return False 1459 return False
1429 1460
1430 query_char = self.path.find('?') 1461 query_char = self.path.find('?')
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
2236 self.option_parser.add_option('--file-root-url', default='/files/', 2267 self.option_parser.add_option('--file-root-url', default='/files/',
2237 help='Specify a root URL for files served.') 2268 help='Specify a root URL for files served.')
2238 # TODO(ricea): Generalize this to support basic auth for HTTP too. 2269 # TODO(ricea): Generalize this to support basic auth for HTTP too.
2239 self.option_parser.add_option('--ws-basic-auth', action='store_true', 2270 self.option_parser.add_option('--ws-basic-auth', action='store_true',
2240 dest='ws_basic_auth', 2271 dest='ws_basic_auth',
2241 help='Enable basic-auth for WebSocket') 2272 help='Enable basic-auth for WebSocket')
2242 2273
2243 2274
2244 if __name__ == '__main__': 2275 if __name__ == '__main__':
2245 sys.exit(ServerRunner().main()) 2276 sys.exit(ServerRunner().main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698