Fix some issues, improve documentation

This commit is contained in:
2021-03-27 19:05:09 +01:00
parent 0f7d67c98d
commit 9036755a62
8 changed files with 89 additions and 48 deletions

View File

@@ -46,20 +46,6 @@ class ResponseHandler(ABC):
def handle(self):
pass
@staticmethod
def parse_uri(uri: str):
parsed = urlsplit(uri)
# If there is no netloc, the url is invalid, so prepend `//` and try again
if parsed.netloc == "":
parsed = urlsplit("//" + uri)
host = parsed.netloc
path = parsed.path
if len(path) == 0 or path[0] != '/':
path = "/" + path
return host, path
class BasicResponseHandler(ResponseHandler):
"""
@@ -98,11 +84,14 @@ class BasicResponseHandler(ResponseHandler):
if 300 <= self.msg.status < 400:
# Redirect
return self._do_handle_redirect()
if 400 <= self.msg.status < 500:
if 400 <= self.msg.status < 600:
# Dump headers and exit with error
print("".join(self.msg.raw), end="")
if not self.cmd.sub_request:
print("".join(self.msg.raw), end="")
return None
return None
def _do_handle_redirect(self):
self._skip_body()