From 7476870acccf2044dff262d5bad06edb12140877 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Thu, 25 Mar 2021 18:26:50 +0100 Subject: [PATCH] client: fix relative paths --- client/response_handler.py | 2 +- httplib/parser.py | 8 +++++++- httplib/retriever.py | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/client/response_handler.py b/client/response_handler.py index 951bf80..be1a976 100644 --- a/client/response_handler.py +++ b/client/response_handler.py @@ -256,7 +256,7 @@ class HTMLDownloadHandler(DownloadHandler): if img_src[0] == "/": img_src = f"http://{self.cmd.host}{img_src}" else: - img_src = os.path.join(base_url, img_src) + img_src = parser.absolute_url(base_url, img_src) if parsed.hostname is None or parsed.hostname == self.cmd.host: port = self.cmd.port diff --git a/httplib/parser.py b/httplib/parser.py index 3bb663d..c62268b 100644 --- a/httplib/parser.py +++ b/httplib/parser.py @@ -1,4 +1,5 @@ import logging +import os.path import re from urllib.parse import urlparse, urlsplit @@ -182,7 +183,6 @@ def parse_headers(lines): headers = [] # first header after the status-line may not contain a space for line in lines: - line = next(lines) if line[0].isspace(): continue else: @@ -251,3 +251,9 @@ def base_url(uri: str): parsed = urlsplit(uri) path = parsed.path.rsplit("/", 1)[0] return f"{parsed.scheme}://{parsed.hostname}{path}/" + + +def absolute_url(uri: str, rel_path: str): + parsed = urlsplit(uri) + path = os.path.normpath(os.path.join(parsed.path, rel_path)) + return f"{parsed.scheme}://{parsed.hostname}{path}" diff --git a/httplib/retriever.py b/httplib/retriever.py index eeaa736..2b9be76 100644 --- a/httplib/retriever.py +++ b/httplib/retriever.py @@ -57,7 +57,7 @@ class PreambleRetriever(Retriever): while True: self.buffer.append(line) - if line in ("\r\n", "\n", " "): + if line in ("\r\n", "\n", ""): break yield line