From b7768671aa03f838b441f72f26109baf0f4176ca Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Thu, 28 Jul 2022 15:38:26 -0400 Subject: [PATCH] http_client: report final resolved url in response Signed-off-by: Eric Callahan --- moonraker/components/http_client.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/moonraker/components/http_client.py b/moonraker/components/http_client.py index fb7bcc9..9b3ba07 100644 --- a/moonraker/components/http_client.py +++ b/moonraker/components/http_client.py @@ -76,7 +76,7 @@ class HttpClient: if len(headers) == 0: raise self.server.error( "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 def escape_url(self, url: str) -> str: @@ -160,10 +160,13 @@ class HttpClient: continue else: 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 else: - ret = HttpResponse(url, 500, b"", HTTPHeaders(), err) + ret = HttpResponse(url, url, 500, b"", HTTPHeaders(), err) if enable_cache and ret.is_cachable(): logging.debug(f"Caching HTTP Response: {url}") self.response_cache[cache_key] = ret @@ -297,12 +300,14 @@ class HttpClient: class HttpResponse: def __init__(self, url: str, + final_url: str, code: int, result: bytes, response_headers: HTTPHeaders, error: Optional[BaseException] ) -> None: self._url = url + self._final_url = final_url self._code = code self._result: bytes = result self._encoding: str = "utf-8" @@ -353,6 +358,10 @@ class HttpResponse: def url(self) -> str: return self._url + @property + def final_url(self) -> str: + return self._final_url + @property def status_code(self) -> int: return self._code