def set_url(self, url): """ Parses a URL specification, and updates the Request's information accordingly. Returns False if the URL was invalid, True if the request succeeded. """ parts = http.parse_url(url) if not parts: return False scheme, host, port, path = parts is_ssl = (True if scheme == "https" else False) self.path = path if host != self.get_host() or port != self.get_port(): if self.flow.change_server: self.flow.change_server((host, port), ssl=is_ssl) else: # There's not live server connection, we're just changing the attributes here. self.flow.server_conn = ServerConnection( (host, port), AddressPriority.MANUALLY_CHANGED) self.flow.server_conn.ssl_established = is_ssl # If this is an absolute request, replace the attributes on the request object as well. if self.host: self.host = host if self.port: self.port = port if self.scheme: self.scheme = scheme return True
def set_url(self, url): """ Parses a URL specification, and updates the Request's information accordingly. Returns False if the URL was invalid, True if the request succeeded. """ parts = http.parse_url(url) if not parts: return False scheme, host, port, path = parts is_ssl = (True if scheme == "https" else False) self.path = path if host != self.get_host() or port != self.get_port(): if self.flow.live: self.flow.live.change_server((host, port), ssl=is_ssl) else: # There's not live server connection, we're just changing the attributes here. self.flow.server_conn = ServerConnection((host, port), proxy.AddressPriority.MANUALLY_CHANGED) self.flow.server_conn.ssl_established = is_ssl # If this is an absolute request, replace the attributes on the request object as well. if self.host: self.host = host if self.port: self.port = port if self.scheme: self.scheme = scheme return True
def new_request(self, url, method): parts = http.parse_url(str(url)) if not parts: self.master.statusbar.message("Invalid Url") return scheme, host, port, path = parts f = self.master.create_request(method, scheme, host, port, path) self.master.view_flow(f)
def new_request(self, url, method): parts = http.parse_url(str(url)) if not parts: signals.status_message.send(message="Invalid Url") return scheme, host, port, path = parts f = self.master.create_request(method, scheme, host, port, path) self.master.view_flow(f)
def url(self, url): """ Parses a URL specification, and updates the Request's information accordingly. Returns False if the URL was invalid, True if the request succeeded. """ parts = http.parse_url(url) if not parts: raise ValueError("Invalid URL: %s" % url) self.scheme, self.host, self.port, self.path = parts
def parse_server_spec(url): p = http.parse_url(url) if not p or not p[1] or p[0] not in ("http", "https"): raise configargparse.ArgumentTypeError( "Invalid server specification: %s" % url) if p[0].lower() == "https": ssl = [True, True] else: ssl = [False, False] return ssl + list(p[1:3])
def parse_server_spec(url): p = http.parse_url(url) if not p or not p[1] or p[0] not in ("http", "https"): raise configargparse.ArgumentTypeError( "Invalid server specification: %s" % url ) if p[0].lower() == "https": ssl = [True, True] else: ssl = [False, False] return ssl + list(p[1:3])
def parse_server_spec(url): normalized_url = re.sub("^https?2", "", url) p = http.parse_url(normalized_url) if not p or not p[1]: raise ArgumentTypeError("Invalid server specification: %s" % url) if url.lower().startswith("https2http"): ssl = [True, False] elif url.lower().startswith("http2https"): ssl = [False, True] elif url.lower().startswith("https"): ssl = [True, True] else: ssl = [False, False] return ssl + list(p[1:3])
def test_parse_url(): assert not http.parse_url("") u = "http://foo.com:8888/test" s, h, po, pa = http.parse_url(u) assert s == "http" assert h == "foo.com" assert po == 8888 assert pa == "/test" s, h, po, pa = http.parse_url("http://foo/bar") assert s == "http" assert h == "foo" assert po == 80 assert pa == "/bar" s, h, po, pa = http.parse_url("http://foo") assert pa == "/" s, h, po, pa = http.parse_url("https://foo") assert po == 443 assert not http.parse_url("https://foo:bar") assert not http.parse_url("https://foo:")
def test_parse_url(): assert not http.parse_url("") u = "http://foo.com:8888/test" s, h, po, pa = http.parse_url(u) assert s == "http" assert h == "foo.com" assert po == 8888 assert pa == "/test" s, h, po, pa = http.parse_url("http://foo/bar") assert s == "http" assert h == "foo" assert po == 80 assert pa == "/bar" s, h, po, pa = http.parse_url("http://*****:*****@foo/bar") assert s == "http" assert h == "foo" assert po == 80 assert pa == "/bar" s, h, po, pa = http.parse_url("http://foo") assert pa == "/" s, h, po, pa = http.parse_url("https://foo") assert po == 443 assert not http.parse_url("https://foo:bar") assert not http.parse_url("https://foo:") # Invalid IDNA assert not http.parse_url("http://\xfafoo") # Invalid PATH assert not http.parse_url("http:/\xc6/localhost:56121") # Null byte in host assert not http.parse_url("http://foo\0") # Port out of range assert not http.parse_url("http://foo:999999") # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt assert not http.parse_url('http://lo[calhost')
def parse_proxy_spec(url): p = http.parse_url(url) if not p or not p[1]: return None return p[:3]
def test_parse_url(): assert not http.parse_url("") u = "http://foo.com:8888/test" s, h, po, pa = http.parse_url(u) assert s == "http" assert h == "foo.com" assert po == 8888 assert pa == "/test" s, h, po, pa = http.parse_url("http://foo/bar") assert s == "http" assert h == "foo" assert po == 80 assert pa == "/bar" s, h, po, pa = http.parse_url("http://foo") assert pa == "/" s, h, po, pa = http.parse_url("https://foo") assert po == 443 assert not http.parse_url("https://foo:bar") assert not http.parse_url("https://foo:") # Invalid IDNA assert not http.parse_url("http://\xfafoo") # Invalid PATH assert not http.parse_url("http:/\xc6/localhost:56121") # Null byte in host assert not http.parse_url("http://foo\0") # Port out of range assert not http.parse_url("http://foo:999999") # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt assert not http.parse_url('http://lo[calhost')