| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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/SYNC/TCP/UDP/ server used for testing Chrome. | 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome. |
| 7 | 7 |
| 8 It supports several test URLs, as specified by the handlers in TestPageHandler. | 8 It supports several test URLs, as specified by the handlers in TestPageHandler. |
| 9 By default, it listens on an ephemeral port and sends the port number back to | 9 By default, it listens on an ephemeral port and sends the port number back to |
| 10 the originating process over a pipe. The originating process can specify an | 10 the originating process over a pipe. The originating process can specify an |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 self.SetCookieHandler, | 336 self.SetCookieHandler, |
| 337 self.AuthBasicHandler, | 337 self.AuthBasicHandler, |
| 338 self.AuthDigestHandler, | 338 self.AuthDigestHandler, |
| 339 self.SlowServerHandler, | 339 self.SlowServerHandler, |
| 340 self.ChunkedServerHandler, | 340 self.ChunkedServerHandler, |
| 341 self.ContentTypeHandler, | 341 self.ContentTypeHandler, |
| 342 self.NoContentHandler, | 342 self.NoContentHandler, |
| 343 self.ServerRedirectHandler, | 343 self.ServerRedirectHandler, |
| 344 self.ClientRedirectHandler, | 344 self.ClientRedirectHandler, |
| 345 self.MultipartHandler, | 345 self.MultipartHandler, |
| 346 self.MultipartSlowHandler, |
| 346 self.DefaultResponseHandler] | 347 self.DefaultResponseHandler] |
| 347 post_handlers = [ | 348 post_handlers = [ |
| 348 self.EchoTitleHandler, | 349 self.EchoTitleHandler, |
| 349 self.EchoAllHandler, | 350 self.EchoAllHandler, |
| 350 self.EchoHandler, | 351 self.EchoHandler, |
| 351 self.DeviceManagementHandler] + get_handlers | 352 self.DeviceManagementHandler] + get_handlers |
| 352 put_handlers = [ | 353 put_handlers = [ |
| 353 self.EchoTitleHandler, | 354 self.EchoTitleHandler, |
| 354 self.EchoAllHandler, | 355 self.EchoAllHandler, |
| 355 self.EchoHandler] + get_handlers | 356 self.EchoHandler] + get_handlers |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 self.send_header('Content-type', 'text/html') | 1284 self.send_header('Content-type', 'text/html') |
| 1284 self.end_headers() | 1285 self.end_headers() |
| 1285 self.wfile.write('<html><head>') | 1286 self.wfile.write('<html><head>') |
| 1286 self.wfile.write('<meta http-equiv="refresh" content="0;url=%s">' % dest) | 1287 self.wfile.write('<meta http-equiv="refresh" content="0;url=%s">' % dest) |
| 1287 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) | 1288 self.wfile.write('</head><body>Redirecting to %s</body></html>' % dest) |
| 1288 | 1289 |
| 1289 return True | 1290 return True |
| 1290 | 1291 |
| 1291 def MultipartHandler(self): | 1292 def MultipartHandler(self): |
| 1292 """Send a multipart response (10 text/html pages).""" | 1293 """Send a multipart response (10 text/html pages).""" |
| 1293 test_name = "/multipart" | 1294 test_name = '/multipart' |
| 1294 if not self._ShouldHandleRequest(test_name): | 1295 if not self._ShouldHandleRequest(test_name): |
| 1295 return False | 1296 return False |
| 1296 | 1297 |
| 1297 num_frames = 10 | 1298 num_frames = 10 |
| 1298 bound = '12345' | 1299 bound = '12345' |
| 1299 self.send_response(200) | 1300 self.send_response(200) |
| 1300 self.send_header('Content-type', | 1301 self.send_header('Content-type', |
| 1301 'multipart/x-mixed-replace;boundary=' + bound) | 1302 'multipart/x-mixed-replace;boundary=' + bound) |
| 1302 self.end_headers() | 1303 self.end_headers() |
| 1303 | 1304 |
| 1304 for i in xrange(num_frames): | 1305 for i in xrange(num_frames): |
| 1305 self.wfile.write('--' + bound + '\r\n') | 1306 self.wfile.write('--' + bound + '\r\n') |
| 1306 self.wfile.write('Content-type: text/html\r\n\r\n') | 1307 self.wfile.write('Content-type: text/html\r\n\r\n') |
| 1307 self.wfile.write('<title>page ' + str(i) + '</title>') | 1308 self.wfile.write('<title>page ' + str(i) + '</title>') |
| 1308 self.wfile.write('page ' + str(i)) | 1309 self.wfile.write('page ' + str(i)) |
| 1309 | 1310 |
| 1310 self.wfile.write('--' + bound + '--') | 1311 self.wfile.write('--' + bound + '--') |
| 1311 return True | 1312 return True |
| 1312 | 1313 |
| 1314 def MultipartSlowHandler(self): |
| 1315 """Send a multipart response (3 text/html pages) with a slight delay |
| 1316 between each page. This is similar to how some pages show status using |
| 1317 multipart.""" |
| 1318 test_name = '/multipart-slow' |
| 1319 if not self._ShouldHandleRequest(test_name): |
| 1320 return False |
| 1321 |
| 1322 num_frames = 3 |
| 1323 bound = '12345' |
| 1324 self.send_response(200) |
| 1325 self.send_header('Content-type', |
| 1326 'multipart/x-mixed-replace;boundary=' + bound) |
| 1327 self.end_headers() |
| 1328 |
| 1329 for i in xrange(num_frames): |
| 1330 self.wfile.write('--' + bound + '\r\n') |
| 1331 self.wfile.write('Content-type: text/html\r\n\r\n') |
| 1332 time.sleep(0.25) |
| 1333 if i == 2: |
| 1334 self.wfile.write('<title>PASS</title>') |
| 1335 else: |
| 1336 self.wfile.write('<title>page ' + str(i) + '</title>') |
| 1337 self.wfile.write('page ' + str(i) + '<!-- ' + ('x' * 2048) + '-->') |
| 1338 |
| 1339 self.wfile.write('--' + bound + '--') |
| 1340 return True |
| 1341 |
| 1313 def DefaultResponseHandler(self): | 1342 def DefaultResponseHandler(self): |
| 1314 """This is the catch-all response handler for requests that aren't handled | 1343 """This is the catch-all response handler for requests that aren't handled |
| 1315 by one of the special handlers above. | 1344 by one of the special handlers above. |
| 1316 Note that we specify the content-length as without it the https connection | 1345 Note that we specify the content-length as without it the https connection |
| 1317 is not closed properly (and the browser keeps expecting data).""" | 1346 is not closed properly (and the browser keeps expecting data).""" |
| 1318 | 1347 |
| 1319 contents = "Default response given for path: " + self.path | 1348 contents = "Default response given for path: " + self.path |
| 1320 self.send_response(200) | 1349 self.send_response(200) |
| 1321 self.send_header('Content-type', 'text/html') | 1350 self.send_header('Content-type', 'text/html') |
| 1322 self.send_header("Content-Length", len(contents)) | 1351 self.send_header("Content-Length", len(contents)) |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1880 'random key if none is specified on the command ' | 1909 'random key if none is specified on the command ' |
| 1881 'line.') | 1910 'line.') |
| 1882 option_parser.add_option('', '--policy-user', default='user@example.com', | 1911 option_parser.add_option('', '--policy-user', default='user@example.com', |
| 1883 dest='policy_user', | 1912 dest='policy_user', |
| 1884 help='Specify the user name the server should ' | 1913 help='Specify the user name the server should ' |
| 1885 'report back to the client as the user owning the ' | 1914 'report back to the client as the user owning the ' |
| 1886 'token used for making the policy request.') | 1915 'token used for making the policy request.') |
| 1887 options, args = option_parser.parse_args() | 1916 options, args = option_parser.parse_args() |
| 1888 | 1917 |
| 1889 sys.exit(main(options, args)) | 1918 sys.exit(main(options, args)) |
| OLD | NEW |