def SetHTTPServerDirectories(self, paths): """Returns True if the HTTP server was started, False otherwise.""" if isinstance(paths, basestring): paths = set([paths]) paths = set(os.path.realpath(p) for p in paths) # If any path is in a subdirectory of another, remove the subdirectory. duplicates = set() for parent_path in paths: for sub_path in paths: if parent_path == sub_path: continue if os.path.commonprefix((parent_path, sub_path)) == parent_path: duplicates.add(sub_path) paths -= duplicates if self.http_server: if paths and self.http_server.paths == paths: return False self.http_server.Close() if not paths: return False server = memory_cache_http_server.MemoryCacheHTTPServer(paths) self.StartLocalServer(server) return True
def SetHTTPServerDirectories(self, paths, handler_class=None): """Returns True if the HTTP server was started, False otherwise.""" # pylint: disable=redefined-variable-type if isinstance(paths, basestring): paths = set([paths]) paths = set(os.path.realpath(p) for p in paths) # If any path is in a subdirectory of another, remove the subdirectory. duplicates = set() for parent_path in paths: for sub_path in paths: if parent_path == sub_path: continue if os.path.commonprefix( (parent_path, sub_path)) == parent_path: duplicates.add(sub_path) paths -= duplicates if self.http_server: old_handler_class = getattr(self.http_server, "dynamic_request_handler_class", None) if not old_handler_class and not handler_class and \ self.http_server.paths == paths: return False if old_handler_class and handler_class \ and old_handler_class.__name__ == handler_class.__name__ \ and self.http_server.paths == paths: return False self.http_server.Close() if not paths: return False if handler_class: server = memory_cache_http_server.MemoryCacheDynamicHTTPServer( paths, handler_class) real_logging.info('MemoryCacheDynamicHTTPServer created') else: server = memory_cache_http_server.MemoryCacheHTTPServer(paths) real_logging.info('MemoryCacheHTTPServer created') self.StartLocalServer(server) # For now, Fuchsia needs to do port forwarding due to --proxy-server # flag not being supported in its browser. # TODO(https://crbug.com/1014670): Remove once debug flags supported in # Fuchsia browsers. if self._platform_backend.GetOSName() == 'fuchsia': self._platform_backend.forwarder_factory.Create( server.port, server.port) return True
def SetHTTPServerDirectories(self, paths, handler_class=None): """Returns True if the HTTP server was started, False otherwise.""" # pylint: disable=redefined-variable-type if isinstance(paths, basestring): paths = set([paths]) paths = set(os.path.realpath(p) for p in paths) # If any path is in a subdirectory of another, remove the subdirectory. duplicates = set() for parent_path in paths: for sub_path in paths: if parent_path == sub_path: continue if os.path.commonprefix((parent_path, sub_path)) == parent_path: duplicates.add(sub_path) paths -= duplicates if self.http_server: old_handler_class = getattr(self.http_server, "dynamic_request_handler_class", None) if not old_handler_class and not handler_class and \ self.http_server.paths == paths: return False if old_handler_class and handler_class \ and old_handler_class.__name__ == handler_class.__name__ \ and self.http_server.paths == paths: return False self.http_server.Close() if not paths: return False if handler_class: server = memory_cache_http_server.MemoryCacheDynamicHTTPServer( paths, handler_class) else: server = memory_cache_http_server.MemoryCacheHTTPServer(paths) self.StartLocalServer(server) return True
def SetHTTPServerDirectories(self, paths): """Returns True if the HTTP server was started, False otherwise.""" if isinstance(paths, basestring): paths = set([paths]) paths = set(os.path.realpath(p) for p in paths) # If any path is in a subdirectory of another, remove the subdirectory. duplicates = set() for parent_path in paths: for sub_path in paths: if parent_path == sub_path: continue if os.path.commonprefix( (parent_path, sub_path)) == parent_path: duplicates.add(sub_path) paths -= duplicates if self.http_server: if paths and self.http_server.paths == paths: return False self.http_server.Close() if not paths: return False server = memory_cache_http_server.MemoryCacheHTTPServer(paths) self.StartLocalServer(server) # Requires port forwarding if platform is on ChromeOS, and # replaces the http_server port number with the one resolved by # remote machine with ssh/adb remote port forwarding. if (self.GetOSName() == 'chromeos' and self._platform_backend.IsRemoteDevice()): self._forwarder = self._platform_backend.CreatePortForwarder( forwarders.PortPair(self.http_server.port, 0), use_remote_port_forwarding=True) self.http_server.port = self._forwarder.host_port return True