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 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 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 def write(self, text) : | 1382 def write(self, text) : |
1383 self.__fd1.write(text) | 1383 self.__fd1.write(text) |
1384 self.__fd2.write(text) | 1384 self.__fd2.write(text) |
1385 | 1385 |
1386 def flush(self) : | 1386 def flush(self) : |
1387 self.__fd1.flush() | 1387 self.__fd1.flush() |
1388 self.__fd2.flush() | 1388 self.__fd2.flush() |
1389 | 1389 |
1390 def main(options, args): | 1390 def main(options, args): |
1391 logfile = open('testserver.log', 'w') | 1391 logfile = open('testserver.log', 'w') |
1392 sys.stdout = FileMultiplexer(sys.stdout, logfile) | |
1393 sys.stderr = FileMultiplexer(sys.stderr, logfile) | 1392 sys.stderr = FileMultiplexer(sys.stderr, logfile) |
| 1393 if options.log_to_console: |
| 1394 sys.stdout = FileMultiplexer(sys.stdout, logfile) |
| 1395 else: |
| 1396 sys.stdout = logfile |
1394 | 1397 |
1395 port = options.port | 1398 port = options.port |
1396 | 1399 |
1397 server_data = {} | 1400 server_data = {} |
1398 | 1401 |
1399 if options.server_type == SERVER_HTTP: | 1402 if options.server_type == SERVER_HTTP: |
1400 if options.cert: | 1403 if options.cert: |
1401 # let's make sure the cert file exists. | 1404 # let's make sure the cert file exists. |
1402 if not os.path.isfile(options.cert): | 1405 if not os.path.isfile(options.cert): |
1403 print 'specified server cert file not found: ' + options.cert + \ | 1406 print 'specified server cert file not found: ' + options.cert + \ |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1482 if __name__ == '__main__': | 1485 if __name__ == '__main__': |
1483 option_parser = optparse.OptionParser() | 1486 option_parser = optparse.OptionParser() |
1484 option_parser.add_option("-f", '--ftp', action='store_const', | 1487 option_parser.add_option("-f", '--ftp', action='store_const', |
1485 const=SERVER_FTP, default=SERVER_HTTP, | 1488 const=SERVER_FTP, default=SERVER_HTTP, |
1486 dest='server_type', | 1489 dest='server_type', |
1487 help='start up an FTP server.') | 1490 help='start up an FTP server.') |
1488 option_parser.add_option('', '--sync', action='store_const', | 1491 option_parser.add_option('', '--sync', action='store_const', |
1489 const=SERVER_SYNC, default=SERVER_HTTP, | 1492 const=SERVER_SYNC, default=SERVER_HTTP, |
1490 dest='server_type', | 1493 dest='server_type', |
1491 help='start up a sync server.') | 1494 help='start up a sync server.') |
| 1495 option_parser.add_option('', '--log-to-console', action='store_const', |
| 1496 const=True, default=False, |
| 1497 dest='log_to_console', |
| 1498 help='Enables or disables sys.stdout logging to ' |
| 1499 'the console.') |
1492 option_parser.add_option('', '--port', default='0', type='int', | 1500 option_parser.add_option('', '--port', default='0', type='int', |
1493 help='Port used by the server. If unspecified, the ' | 1501 help='Port used by the server. If unspecified, the ' |
1494 'server will listen on an ephemeral port.') | 1502 'server will listen on an ephemeral port.') |
1495 option_parser.add_option('', '--data-dir', dest='data_dir', | 1503 option_parser.add_option('', '--data-dir', dest='data_dir', |
1496 help='Directory from which to read the files.') | 1504 help='Directory from which to read the files.') |
1497 option_parser.add_option('', '--https', dest='cert', | 1505 option_parser.add_option('', '--https', dest='cert', |
1498 help='Specify that https should be used, specify ' | 1506 help='Specify that https should be used, specify ' |
1499 'the path to the cert containing the private key ' | 1507 'the path to the cert containing the private key ' |
1500 'the server should use.') | 1508 'the server should use.') |
1501 option_parser.add_option('', '--ssl-client-auth', action='store_true', | 1509 option_parser.add_option('', '--ssl-client-auth', action='store_true', |
(...skipping 20 matching lines...) Expand all Loading... |
1522 option_parser.add_option('', '--policy-cert-chain', action='append', | 1530 option_parser.add_option('', '--policy-cert-chain', action='append', |
1523 help='Specify a path to a certificate file to sign ' | 1531 help='Specify a path to a certificate file to sign ' |
1524 'policy responses. This option may be used ' | 1532 'policy responses. This option may be used ' |
1525 'multiple times to define a certificate chain. ' | 1533 'multiple times to define a certificate chain. ' |
1526 'The first element will be used for signing, ' | 1534 'The first element will be used for signing, ' |
1527 'the last element should be the root ' | 1535 'the last element should be the root ' |
1528 'certificate.') | 1536 'certificate.') |
1529 options, args = option_parser.parse_args() | 1537 options, args = option_parser.parse_args() |
1530 | 1538 |
1531 sys.exit(main(options, args)) | 1539 sys.exit(main(options, args)) |
OLD | NEW |