| 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 errno | 8 import errno |
| 9 import gzip | 9 import gzip |
| 10 import hashlib | 10 import hashlib |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 return SimpleHTTPServer.SimpleHTTPRequestHandler.guess_type(self, path) | 164 return SimpleHTTPServer.SimpleHTTPRequestHandler.guess_type(self, path) |
| 165 | 165 |
| 166 def log_message(self, *_): | 166 def log_message(self, *_): |
| 167 """Override the base class method to disable logging.""" | 167 """Override the base class method to disable logging.""" |
| 168 pass | 168 pass |
| 169 | 169 |
| 170 RequestHandler.protocol_version = 'HTTP/1.1' | 170 RequestHandler.protocol_version = 'HTTP/1.1' |
| 171 return RequestHandler | 171 return RequestHandler |
| 172 | 172 |
| 173 | 173 |
| 174 def StartHttpServer(local_dir_path, host_port=0, additional_mappings=None): | 174 def start_http_server(local_dir_path, host_port=0, additional_mappings=None): |
| 175 """Starts an http server serving files from |local_dir_path| on |host_port|. | 175 """Starts an http server serving files from |local_dir_path| on |host_port|. |
| 176 | 176 |
| 177 Args: | 177 Args: |
| 178 local_dir_path: Path to the local filesystem directory to be served over | 178 local_dir_path: Path to the local filesystem directory to be served over |
| 179 http under. | 179 http under. |
| 180 host_port: Port on the host machine to run the server on. Pass 0 to use a | 180 host_port: Port on the host machine to run the server on. Pass 0 to use a |
| 181 system-assigned port. | 181 system-assigned port. |
| 182 additional_mappings: List of tuples (prefix, local_base_path) mapping | 182 additional_mappings: List of tuples (prefix, local_base_path) mapping |
| 183 URLs that start with |prefix| to local directory at |local_base_path|. | 183 URLs that start with |prefix| to local directory at |local_base_path|. |
| 184 The prefixes should skip the leading slash. | 184 The prefixes should skip the leading slash. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 return httpd.server_address | 204 return httpd.server_address |
| 205 except socket.error as v: | 205 except socket.error as v: |
| 206 error_code = v[0] | 206 error_code = v[0] |
| 207 print 'Failed to start http server for %s on port %d: %s.' % ( | 207 print 'Failed to start http server for %s on port %d: %s.' % ( |
| 208 local_dir_path, host_port, os.strerror(error_code)) | 208 local_dir_path, host_port, os.strerror(error_code)) |
| 209 if error_code == errno.EADDRINUSE: | 209 if error_code == errno.EADDRINUSE: |
| 210 print (' Run `fuser %d/tcp` to find out which process is using the port.' | 210 print (' Run `fuser %d/tcp` to find out which process is using the port.' |
| 211 % host_port) | 211 % host_port) |
| 212 print '---' | 212 print '---' |
| 213 raise | 213 raise |
| OLD | NEW |