client: fix relative paths

This commit is contained in:
2021-03-25 18:26:50 +01:00
parent f15ff38f69
commit 7476870acc
3 changed files with 9 additions and 3 deletions

View File

@@ -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

View File

@@ -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}"