| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path)) | 133 SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path)) |
| 134 | 134 |
| 135 for prefix, local_base_path in mappings: | 135 for prefix, local_base_path in mappings: |
| 136 if normalized_path.startswith(prefix): | 136 if normalized_path.startswith(prefix): |
| 137 return os.path.join(local_base_path, normalized_path[len(prefix):]) | 137 return os.path.join(local_base_path, normalized_path[len(prefix):]) |
| 138 | 138 |
| 139 # This class is only used internally, and we're adding a catch-all '' | 139 # This class is only used internally, and we're adding a catch-all '' |
| 140 # prefix at the end of |mappings|. | 140 # prefix at the end of |mappings|. |
| 141 assert False | 141 assert False |
| 142 | 142 |
| 143 def guess_type(self, path): |
| 144 if path.endswith('.dart'): |
| 145 return 'application/dart' |
| 146 elif path.endswith('.sky'): |
| 147 return 'text/sky' |
| 148 return SimpleHTTPServer.SimpleHTTPRequestHandler.guess_type(self, path) |
| 149 |
| 143 def log_message(self, *_): | 150 def log_message(self, *_): |
| 144 """Override the base class method to disable logging.""" | 151 """Override the base class method to disable logging.""" |
| 145 pass | 152 pass |
| 146 | 153 |
| 147 RequestHandler.protocol_version = 'HTTP/1.1' | 154 RequestHandler.protocol_version = 'HTTP/1.1' |
| 148 return RequestHandler | 155 return RequestHandler |
| 149 | 156 |
| 150 | 157 |
| 151 def StartHttpServer(local_dir_path, host_port=0, additional_mappings=None): | 158 def StartHttpServer(local_dir_path, host_port=0, additional_mappings=None): |
| 152 """Starts an http server serving files from |local_dir_path| on |host_port|. | 159 """Starts an http server serving files from |local_dir_path| on |host_port|. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 168 mappings.append(('', local_dir_path)) | 175 mappings.append(('', local_dir_path)) |
| 169 handler_class = _GetHandlerClassForPath(mappings) | 176 handler_class = _GetHandlerClassForPath(mappings) |
| 170 | 177 |
| 171 httpd = _SilentTCPServer(('127.0.0.1', host_port), handler_class) | 178 httpd = _SilentTCPServer(('127.0.0.1', host_port), handler_class) |
| 172 atexit.register(httpd.shutdown) | 179 atexit.register(httpd.shutdown) |
| 173 | 180 |
| 174 http_thread = threading.Thread(target=httpd.serve_forever) | 181 http_thread = threading.Thread(target=httpd.serve_forever) |
| 175 http_thread.daemon = True | 182 http_thread.daemon = True |
| 176 http_thread.start() | 183 http_thread.start() |
| 177 return httpd.server_address | 184 return httpd.server_address |
| OLD | NEW |