OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 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 It defaults to living on localhost:8888. | 9 It defaults to living on localhost:8888. |
10 It can use https if you specify the flag --https=CERT where CERT is the path | 10 It can use https if you specify the flag --https=CERT where CERT is the path |
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 self.send_response(200) | 558 self.send_response(200) |
559 self.send_header('Content-type', 'text/html') | 559 self.send_header('Content-type', 'text/html') |
560 self.send_header('Cache-Control', 'max-age=0') | 560 self.send_header('Cache-Control', 'max-age=0') |
561 self.end_headers() | 561 self.end_headers() |
562 return True | 562 return True |
563 | 563 |
564 def FileHandler(self): | 564 def FileHandler(self): |
565 """This handler sends the contents of the requested file. Wow, it's like | 565 """This handler sends the contents of the requested file. Wow, it's like |
566 a real webserver!""" | 566 a real webserver!""" |
567 | 567 |
568 prefix='/files/' | 568 prefix = self.server.file_root_url |
569 if not self.path.startswith(prefix): | 569 if not self.path.startswith(prefix): |
570 return False | 570 return False |
571 | 571 |
572 file = self.path[len(prefix):] | 572 file = self.path[len(prefix):] |
573 entries = file.split('/'); | 573 entries = file.split('/'); |
574 path = os.path.join(self.server.data_dir, *entries) | 574 path = os.path.join(self.server.data_dir, *entries) |
| 575 if os.path.isdir(path): |
| 576 path = os.path.join(path, 'index.html') |
575 | 577 |
576 if not os.path.isfile(path): | 578 if not os.path.isfile(path): |
577 print "File not found " + file + " full path:" + path | 579 print "File not found " + file + " full path:" + path |
578 self.send_error(404) | 580 self.send_error(404) |
579 return True | 581 return True |
580 | 582 |
581 f = open(path, "rb") | 583 f = open(path, "rb") |
582 data = f.read() | 584 data = f.read() |
583 f.close() | 585 f.close() |
584 | 586 |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 if not os.path.isfile(options.cert): | 1042 if not os.path.isfile(options.cert): |
1041 print 'specified cert file not found: ' + options.cert + ' exiting...' | 1043 print 'specified cert file not found: ' + options.cert + ' exiting...' |
1042 return | 1044 return |
1043 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert) | 1045 server = HTTPSServer(('127.0.0.1', port), TestPageHandler, options.cert) |
1044 print 'HTTPS server started on port %d...' % port | 1046 print 'HTTPS server started on port %d...' % port |
1045 else: | 1047 else: |
1046 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler) | 1048 server = StoppableHTTPServer(('127.0.0.1', port), TestPageHandler) |
1047 print 'HTTP server started on port %d...' % port | 1049 print 'HTTP server started on port %d...' % port |
1048 | 1050 |
1049 server.data_dir = MakeDataDir() | 1051 server.data_dir = MakeDataDir() |
| 1052 server.file_root_url = options.file_root_url |
1050 MakeDumpDir(server.data_dir) | 1053 MakeDumpDir(server.data_dir) |
1051 | 1054 |
1052 # means FTP Server | 1055 # means FTP Server |
1053 else: | 1056 else: |
1054 my_data_dir = MakeDataDir() | 1057 my_data_dir = MakeDataDir() |
1055 | 1058 |
1056 def line_logger(msg): | 1059 def line_logger(msg): |
1057 if (msg.find("kill") >= 0): | 1060 if (msg.find("kill") >= 0): |
1058 server.stop = True | 1061 server.stop = True |
1059 print 'shutting down server' | 1062 print 'shutting down server' |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 dest='server_type', | 1098 dest='server_type', |
1096 help='FTP or HTTP server default HTTP') | 1099 help='FTP or HTTP server default HTTP') |
1097 option_parser.add_option('', '--port', default='8888', type='int', | 1100 option_parser.add_option('', '--port', default='8888', type='int', |
1098 help='Port used by the server') | 1101 help='Port used by the server') |
1099 option_parser.add_option('', '--data-dir', dest='data_dir', | 1102 option_parser.add_option('', '--data-dir', dest='data_dir', |
1100 help='Directory from which to read the files') | 1103 help='Directory from which to read the files') |
1101 option_parser.add_option('', '--https', dest='cert', | 1104 option_parser.add_option('', '--https', dest='cert', |
1102 help='Specify that https should be used, specify ' | 1105 help='Specify that https should be used, specify ' |
1103 'the path to the cert containing the private key ' | 1106 'the path to the cert containing the private key ' |
1104 'the server should use') | 1107 'the server should use') |
| 1108 option_parser.add_option('', '--file-root-url', default='/files/', |
| 1109 help='Specify a root URL for files served.') |
1105 options, args = option_parser.parse_args() | 1110 options, args = option_parser.parse_args() |
1106 | 1111 |
1107 sys.exit(main(options, args)) | 1112 sys.exit(main(options, args)) |
OLD | NEW |