small fixes

This commit is contained in:
2021-03-27 17:32:16 +01:00
parent ff32ce9b39
commit 0f7d67c98d
2 changed files with 14 additions and 5 deletions

View File

@@ -62,9 +62,10 @@ class ResponseHandler(ABC):
class BasicResponseHandler(ResponseHandler):
""" Response handler which throws away the body and only shows the headers.
"""
Response handler which throws away the body and only shows the headers.
In case of a redirect, it will process it and pass it to the appropriate response handler.
"""
"""
def __init__(self, client: HTTPClient, msg: Message, cmd: AbstractCommand):
retriever = Retriever.create(client, msg.headers)
@@ -105,10 +106,15 @@ class BasicResponseHandler(ResponseHandler):
def _do_handle_redirect(self):
self._skip_body()
if self.msg.status == 304:
print("".join(self.msg.raw), end="")
return None
location = self.msg.headers.get("location")
if not location:
if not location or len(location.strip()) == 0:
raise InvalidResponse("No location in redirect")
location = parser.urljoin(self.cmd.uri, location)
parsed_location = urlsplit(location)
if not parsed_location.hostname:
raise InvalidResponse("Invalid location")