| OLD | NEW |
| 1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2010 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 server used for testing Chrome. | 6 """This is a simple HTTP 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 import md5 | 42 import md5 |
| 43 _new_md5 = md5.new | 43 _new_md5 = md5.new |
| 44 | 44 |
| 45 if sys.platform == 'win32': | 45 if sys.platform == 'win32': |
| 46 import msvcrt | 46 import msvcrt |
| 47 | 47 |
| 48 SERVER_HTTP = 0 | 48 SERVER_HTTP = 0 |
| 49 SERVER_FTP = 1 | 49 SERVER_FTP = 1 |
| 50 SERVER_SYNC = 2 | 50 SERVER_SYNC = 2 |
| 51 | 51 |
| 52 # Using debug() seems to cause hangs on XP: see http://crbug.com/64515 . |
| 52 debug_output = sys.stderr | 53 debug_output = sys.stderr |
| 53 def debug(str): | 54 def debug(str): |
| 54 debug_output.write(str + "\n") | 55 debug_output.write(str + "\n") |
| 55 debug_output.flush() | 56 debug_output.flush() |
| 56 | 57 |
| 57 class StoppableHTTPServer(BaseHTTPServer.HTTPServer): | 58 class StoppableHTTPServer(BaseHTTPServer.HTTPServer): |
| 58 """This is a specialization of of BaseHTTPServer to allow it | 59 """This is a specialization of of BaseHTTPServer to allow it |
| 59 to be exited cleanly (by setting its "stop" member to True).""" | 60 to be exited cleanly (by setting its "stop" member to True).""" |
| 60 | 61 |
| 61 def serve_forever(self): | 62 def serve_forever(self): |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 listen_port = server.socket.getsockname()[1] | 1320 listen_port = server.socket.getsockname()[1] |
| 1320 print 'FTP server started on port %d...' % listen_port | 1321 print 'FTP server started on port %d...' % listen_port |
| 1321 | 1322 |
| 1322 # Notify the parent that we've started. (BaseServer subclasses | 1323 # Notify the parent that we've started. (BaseServer subclasses |
| 1323 # bind their sockets on construction.) | 1324 # bind their sockets on construction.) |
| 1324 if options.startup_pipe is not None: | 1325 if options.startup_pipe is not None: |
| 1325 server_data = { | 1326 server_data = { |
| 1326 'port': listen_port | 1327 'port': listen_port |
| 1327 } | 1328 } |
| 1328 server_data_json = simplejson.dumps(server_data) | 1329 server_data_json = simplejson.dumps(server_data) |
| 1330 server_data_len = len(server_data_json) |
| 1331 print 'sending server_data: %s (%d bytes)' % ( |
| 1332 server_data_json, server_data_len) |
| 1329 if sys.platform == 'win32': | 1333 if sys.platform == 'win32': |
| 1330 fd = msvcrt.open_osfhandle(options.startup_pipe, 0) | 1334 fd = msvcrt.open_osfhandle(options.startup_pipe, 0) |
| 1331 else: | 1335 else: |
| 1332 fd = options.startup_pipe | 1336 fd = options.startup_pipe |
| 1333 startup_pipe = os.fdopen(fd, "w") | 1337 startup_pipe = os.fdopen(fd, "w") |
| 1334 # Write the listening port as a 2 byte value. This is _not_ using | 1338 # First write the data length as an unsigned 4-byte value. This |
| 1335 # network byte ordering since the other end of the pipe is on the same | 1339 # is _not_ using network byte ordering since the other end of the |
| 1336 # machine. | 1340 # pipe is on the same machine. |
| 1337 startup_pipe.write(struct.pack('@H', listen_port)) | 1341 startup_pipe.write(struct.pack('=L', server_data_len)) |
| 1342 startup_pipe.write(server_data_json) |
| 1338 startup_pipe.close() | 1343 startup_pipe.close() |
| 1339 | 1344 |
| 1340 try: | 1345 try: |
| 1341 server.serve_forever() | 1346 server.serve_forever() |
| 1342 except KeyboardInterrupt: | 1347 except KeyboardInterrupt: |
| 1343 print 'shutting down server' | 1348 print 'shutting down server' |
| 1344 server.stop = True | 1349 server.stop = True |
| 1345 | 1350 |
| 1346 if __name__ == '__main__': | 1351 if __name__ == '__main__': |
| 1347 option_parser = optparse.OptionParser() | 1352 option_parser = optparse.OptionParser() |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 'option may appear multiple times, indicating ' | 1384 'option may appear multiple times, indicating ' |
| 1380 'multiple algorithms should be enabled.'); | 1385 'multiple algorithms should be enabled.'); |
| 1381 option_parser.add_option('', '--file-root-url', default='/files/', | 1386 option_parser.add_option('', '--file-root-url', default='/files/', |
| 1382 help='Specify a root URL for files served.') | 1387 help='Specify a root URL for files served.') |
| 1383 option_parser.add_option('', '--startup-pipe', type='int', | 1388 option_parser.add_option('', '--startup-pipe', type='int', |
| 1384 dest='startup_pipe', | 1389 dest='startup_pipe', |
| 1385 help='File handle of pipe to parent process') | 1390 help='File handle of pipe to parent process') |
| 1386 options, args = option_parser.parse_args() | 1391 options, args = option_parser.parse_args() |
| 1387 | 1392 |
| 1388 sys.exit(main(options, args)) | 1393 sys.exit(main(options, args)) |
| OLD | NEW |