| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import atexit | 5 import atexit |
| 6 import datetime | 6 import datetime |
| 7 import email.utils | 7 import email.utils |
| 8 import hashlib | 8 import hashlib |
| 9 import logging | 9 import logging |
| 10 import math | 10 import math |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 return os.path.join(base_path, os.path.relpath(path_from_current)) | 119 return os.path.join(base_path, os.path.relpath(path_from_current)) |
| 120 | 120 |
| 121 def log_message(self, *_): | 121 def log_message(self, *_): |
| 122 """Override the base class method to disable logging.""" | 122 """Override the base class method to disable logging.""" |
| 123 pass | 123 pass |
| 124 | 124 |
| 125 RequestHandler.protocol_version = 'HTTP/1.1' | 125 RequestHandler.protocol_version = 'HTTP/1.1' |
| 126 return RequestHandler | 126 return RequestHandler |
| 127 | 127 |
| 128 | 128 |
| 129 def StartHttpServer(path): | 129 def StartHttpServer(local_dir_path, host_port=0): |
| 130 """Starts an http server serving files from |path| on random | 130 """Starts an http server serving files from |path| on |host_port|. Pass 0 |
| 131 (system-allocated) port. Returns the server address. | 131 as |host_port| to use a system-allocated port. |
| 132 |
| 133 Returns: |
| 134 Tuple of the server address and the port on which it runs. |
| 132 """ | 135 """ |
| 133 assert path | 136 assert local_dir_path |
| 134 httpd = _SilentTCPServer(('127.0.0.1', 0), _GetHandlerClassForPath(path)) | 137 httpd = _SilentTCPServer(('127.0.0.1', host_port), |
| 138 _GetHandlerClassForPath(local_dir_path)) |
| 135 atexit.register(httpd.shutdown) | 139 atexit.register(httpd.shutdown) |
| 136 | 140 |
| 137 http_thread = threading.Thread(target=httpd.serve_forever) | 141 http_thread = threading.Thread(target=httpd.serve_forever) |
| 138 http_thread.daemon = True | 142 http_thread.daemon = True |
| 139 http_thread.start() | 143 http_thread.start() |
| 140 return httpd.server_address | 144 return httpd.server_address |
| OLD | NEW |