| 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 hashlib | 9 import hashlib |
| 10 import logging | 10 import logging |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 pass | 200 pass |
| 201 | 201 |
| 202 def __del__(self): | 202 def __del__(self): |
| 203 if self.gzipped_file_name: | 203 if self.gzipped_file_name: |
| 204 os.remove(self.gzipped_file_name) | 204 os.remove(self.gzipped_file_name) |
| 205 | 205 |
| 206 RequestHandler.protocol_version = 'HTTP/1.1' | 206 RequestHandler.protocol_version = 'HTTP/1.1' |
| 207 return RequestHandler | 207 return RequestHandler |
| 208 | 208 |
| 209 | 209 |
| 210 def start_http_server(mappings, host_port=0): | 210 def start_http_server(mappings, host_port): |
| 211 """Starts an http server serving files from |local_dir_path| on |host_port|. | 211 """Starts an http server serving files from |local_dir_path| on |host_port|. |
| 212 | 212 |
| 213 Args: | 213 Args: |
| 214 mappings: List of tuples (prefix, local_base_path_list) mapping URLs that | 214 mappings: List of tuples (prefix, local_base_path_list) mapping URLs that |
| 215 start with |prefix| to one or more local directories enumerated in | 215 start with |prefix| to one or more local directories enumerated in |
| 216 |local_base_path_list|. The prefixes should skip the leading slash. | 216 |local_base_path_list|. The prefixes should skip the leading slash. |
| 217 The first matching prefix and the first location that contains the | 217 The first matching prefix and the first location that contains the |
| 218 requested file will be used each time. | 218 requested file will be used each time. |
| 219 host_port: Port on the host machine to run the server on. Pass 0 to use a | 219 host_port: Port on the host machine to run the server on. Pass 0 to use a |
| 220 system-assigned port. | 220 system-assigned port. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 244 'lsof -i :%d | grep LISTEN | awk \'{print $2}\' | xargs kill -9' | 244 'lsof -i :%d | grep LISTEN | awk \'{print $2}\' | xargs kill -9' |
| 245 % host_port) | 245 % host_port) |
| 246 else: | 246 else: |
| 247 find_cmd = 'fuser %d/tcp' % host_port | 247 find_cmd = 'fuser %d/tcp' % host_port |
| 248 terminate_cmd = 'fuser -k %d/tcp' % host_port | 248 terminate_cmd = 'fuser -k %d/tcp' % host_port |
| 249 print (' Run `%s` to find out which process is using the port;' | 249 print (' Run `%s` to find out which process is using the port;' |
| 250 % find_cmd) | 250 % find_cmd) |
| 251 print (' or `%s` terminate it.' % terminate_cmd) | 251 print (' or `%s` terminate it.' % terminate_cmd) |
| 252 print '---' | 252 print '---' |
| 253 raise | 253 raise |
| OLD | NEW |