OLD | NEW |
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 1576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1587 |
1588 if not self._ShouldHandleRequest("/device_management"): | 1588 if not self._ShouldHandleRequest("/device_management"): |
1589 return False | 1589 return False |
1590 | 1590 |
1591 raw_request = self.ReadRequestBody() | 1591 raw_request = self.ReadRequestBody() |
1592 | 1592 |
1593 if not self.server._device_management_handler: | 1593 if not self.server._device_management_handler: |
1594 import device_management | 1594 import device_management |
1595 policy_path = os.path.join(self.server.data_dir, 'device_management') | 1595 policy_path = os.path.join(self.server.data_dir, 'device_management') |
1596 self.server._device_management_handler = ( | 1596 self.server._device_management_handler = ( |
1597 device_management.TestServer(policy_path, self.server.policy_keys)) | 1597 device_management.TestServer(policy_path)) |
1598 | 1598 |
1599 http_response, raw_reply = ( | 1599 http_response, raw_reply = ( |
1600 self.server._device_management_handler.HandleRequest(self.path, | 1600 self.server._device_management_handler.HandleRequest(self.path, |
1601 self.headers, | 1601 self.headers, |
1602 raw_request)) | 1602 raw_request)) |
1603 self.send_response(http_response) | 1603 self.send_response(http_response) |
1604 if (http_response == 200): | 1604 if (http_response == 200): |
1605 self.send_header('Content-Type', 'application/x-protobuffer') | 1605 self.send_header('Content-Type', 'application/x-protobuffer') |
1606 self.end_headers() | 1606 self.end_headers() |
1607 self.wfile.write(raw_reply) | 1607 self.wfile.write(raw_reply) |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 self.options.tls_intolerant) | 1876 self.options.tls_intolerant) |
1877 print 'HTTPS server started on %s:%d...' % (host, server.server_port) | 1877 print 'HTTPS server started on %s:%d...' % (host, server.server_port) |
1878 else: | 1878 else: |
1879 server = HTTPServer((host, port), TestPageHandler) | 1879 server = HTTPServer((host, port), TestPageHandler) |
1880 print 'HTTP server started on %s:%d...' % (host, server.server_port) | 1880 print 'HTTP server started on %s:%d...' % (host, server.server_port) |
1881 | 1881 |
1882 server.data_dir = self.__make_data_dir() | 1882 server.data_dir = self.__make_data_dir() |
1883 server.file_root_url = self.options.file_root_url | 1883 server.file_root_url = self.options.file_root_url |
1884 server_data['port'] = server.server_port | 1884 server_data['port'] = server.server_port |
1885 server._device_management_handler = None | 1885 server._device_management_handler = None |
1886 server.policy_keys = self.options.policy_keys | |
1887 elif self.options.server_type == SERVER_WEBSOCKET: | 1886 elif self.options.server_type == SERVER_WEBSOCKET: |
1888 # Launch pywebsocket via WebSocketServer. | 1887 # Launch pywebsocket via WebSocketServer. |
1889 logger = logging.getLogger() | 1888 logger = logging.getLogger() |
1890 logger.addHandler(logging.StreamHandler()) | 1889 logger.addHandler(logging.StreamHandler()) |
1891 # TODO(toyoshim): Remove following os.chdir. Currently this operation | 1890 # TODO(toyoshim): Remove following os.chdir. Currently this operation |
1892 # is required to work correctly. It should be fixed from pywebsocket side. | 1891 # is required to work correctly. It should be fixed from pywebsocket side. |
1893 os.chdir(self.__make_data_dir()) | 1892 os.chdir(self.__make_data_dir()) |
1894 websocket_options = WebSocketOptions(host, port, '.') | 1893 websocket_options = WebSocketOptions(host, port, '.') |
1895 if self.options.cert_and_key_file: | 1894 if self.options.cert_and_key_file: |
1896 websocket_options.use_tls = True | 1895 websocket_options.use_tls = True |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 self.option_parser.add_option('--ssl-bulk-cipher', action='append', | 2028 self.option_parser.add_option('--ssl-bulk-cipher', action='append', |
2030 help='Specify the bulk encryption ' | 2029 help='Specify the bulk encryption ' |
2031 'algorithm(s) that will be accepted by the ' | 2030 'algorithm(s) that will be accepted by the ' |
2032 'SSL server. Valid values are "aes256", ' | 2031 'SSL server. Valid values are "aes256", ' |
2033 '"aes128", "3des", "rc4". If omitted, all ' | 2032 '"aes128", "3des", "rc4". If omitted, all ' |
2034 'algorithms will be used. This option may ' | 2033 'algorithms will be used. This option may ' |
2035 'appear multiple times, indicating ' | 2034 'appear multiple times, indicating ' |
2036 'multiple algorithms should be enabled.'); | 2035 'multiple algorithms should be enabled.'); |
2037 self.option_parser.add_option('--file-root-url', default='/files/', | 2036 self.option_parser.add_option('--file-root-url', default='/files/', |
2038 help='Specify a root URL for files served.') | 2037 help='Specify a root URL for files served.') |
2039 self.option_parser.add_option('--policy-key', action='append', | |
2040 dest='policy_keys', | |
2041 help='Specify a path to a PEM-encoded ' | |
2042 'private key to use for policy signing. May ' | |
2043 'be specified multiple times in order to ' | |
2044 'load multipe keys into the server. If the ' | |
2045 'server has multiple keys, it will rotate ' | |
2046 'through them in at each request a ' | |
2047 'round-robin fashion. The server will ' | |
2048 'generate a random key if none is specified ' | |
2049 'on the command line.') | |
2050 | 2038 |
2051 | 2039 |
2052 if __name__ == '__main__': | 2040 if __name__ == '__main__': |
2053 sys.exit(ServerRunner().main()) | 2041 sys.exit(ServerRunner().main()) |
OLD | NEW |