http_client: report final resolved url in response
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
12161d12f5
commit
b7768671aa
|
@ -76,7 +76,7 @@ class HttpClient:
|
||||||
if len(headers) == 0:
|
if len(headers) == 0:
|
||||||
raise self.server.error(
|
raise self.server.error(
|
||||||
"Either an Etag or Last Modified Date must be specified")
|
"Either an Etag or Last Modified Date must be specified")
|
||||||
empty_resp = HttpResponse(url, 200, b"", headers, None)
|
empty_resp = HttpResponse(url, url, 200, b"", headers, None)
|
||||||
self.response_cache[url] = empty_resp
|
self.response_cache[url] = empty_resp
|
||||||
|
|
||||||
def escape_url(self, url: str) -> str:
|
def escape_url(self, url: str) -> str:
|
||||||
|
@ -160,10 +160,13 @@ class HttpClient:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
result = resp.body
|
result = resp.body
|
||||||
ret = HttpResponse(url, resp.code, result, resp.headers, err)
|
ret = HttpResponse(
|
||||||
|
url, resp.effective_url, resp.code, result,
|
||||||
|
resp.headers, err
|
||||||
|
)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
ret = HttpResponse(url, 500, b"", HTTPHeaders(), err)
|
ret = HttpResponse(url, url, 500, b"", HTTPHeaders(), err)
|
||||||
if enable_cache and ret.is_cachable():
|
if enable_cache and ret.is_cachable():
|
||||||
logging.debug(f"Caching HTTP Response: {url}")
|
logging.debug(f"Caching HTTP Response: {url}")
|
||||||
self.response_cache[cache_key] = ret
|
self.response_cache[cache_key] = ret
|
||||||
|
@ -297,12 +300,14 @@ class HttpClient:
|
||||||
class HttpResponse:
|
class HttpResponse:
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
url: str,
|
url: str,
|
||||||
|
final_url: str,
|
||||||
code: int,
|
code: int,
|
||||||
result: bytes,
|
result: bytes,
|
||||||
response_headers: HTTPHeaders,
|
response_headers: HTTPHeaders,
|
||||||
error: Optional[BaseException]
|
error: Optional[BaseException]
|
||||||
) -> None:
|
) -> None:
|
||||||
self._url = url
|
self._url = url
|
||||||
|
self._final_url = final_url
|
||||||
self._code = code
|
self._code = code
|
||||||
self._result: bytes = result
|
self._result: bytes = result
|
||||||
self._encoding: str = "utf-8"
|
self._encoding: str = "utf-8"
|
||||||
|
@ -353,6 +358,10 @@ class HttpResponse:
|
||||||
def url(self) -> str:
|
def url(self) -> str:
|
||||||
return self._url
|
return self._url
|
||||||
|
|
||||||
|
@property
|
||||||
|
def final_url(self) -> str:
|
||||||
|
return self._final_url
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def status_code(self) -> int:
|
def status_code(self) -> int:
|
||||||
return self._code
|
return self._code
|
||||||
|
|
Loading…
Reference in New Issue