http_client: remove escape_url method
This method will not work correctly if any individual part contains a special character. For example, if an item in the path contains a "#", the regex will return an incorrect result. Likewise, if any item in a query string contains an "&" the query string will be correctly escaped. All urls supplied to the http client must be escaped by the consumer. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
0b4e604c95
commit
9b9a6d0646
|
@ -40,18 +40,6 @@ AsyncHTTPClient.configure(
|
|||
|
||||
GITHUB_PREFIX = "https://api.github.com/"
|
||||
|
||||
def escape_query_string(qs: str) -> str:
|
||||
parts = qs.split("&")
|
||||
escaped: List[str] = []
|
||||
for p in parts:
|
||||
item = p.split("=", 1)
|
||||
key = url_escape(item[0])
|
||||
if len(item) == 2:
|
||||
escaped.append(f"{key}={url_escape(item[1])}")
|
||||
else:
|
||||
escaped.append(key)
|
||||
return "&".join(escaped)
|
||||
|
||||
class HttpClient:
|
||||
def __init__(self, config: ConfigHelper) -> None:
|
||||
self.server = config.get_server()
|
||||
|
@ -79,21 +67,6 @@ class HttpClient:
|
|||
empty_resp = HttpResponse(url, url, 200, b"", headers, None)
|
||||
self.response_cache[url] = empty_resp
|
||||
|
||||
def escape_url(self, url: str) -> str:
|
||||
# escape the url
|
||||
match = re.match(r"(https?://[^/?#]+)([^?#]+)?(\?[^#]+)?(#.+)?", url)
|
||||
if match is not None:
|
||||
uri, path, qs, fragment = match.groups()
|
||||
if path is not None:
|
||||
uri += "/".join([url_escape(p, plus=False)
|
||||
for p in path.split("/")])
|
||||
if qs is not None:
|
||||
uri += "?" + escape_query_string(qs[1:])
|
||||
if fragment is not None:
|
||||
uri += "#" + url_escape(fragment[1:], plus=False)
|
||||
url = uri
|
||||
return url
|
||||
|
||||
async def request(
|
||||
self,
|
||||
method: str,
|
||||
|
|
Loading…
Reference in New Issue