From 8613cc02064fce9cbe28ed1c5b31f27d63b3d8b0 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sun, 18 Aug 2019 11:48:18 +0200 Subject: [PATCH] Fix proxy --- app.py | 2 ++ utils/template_filters.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/app.py b/app.py index b50d6c3..9ed4622 100644 --- a/app.py +++ b/app.py @@ -4,6 +4,7 @@ import os import traceback from datetime import datetime from typing import Any +from urllib.parse import urlparse from uuid import uuid4 import requests @@ -242,6 +243,7 @@ def proxy(url: str) -> Any: for k, v in dict(request.headers).items() if k.lower() not in ["host", "cookie"] } + req_headers["Host"] = urlparse(url).netloc resp = requests.get(url, stream=True, headers=req_headers) app.logger.info(f"proxied req {url}: {resp!r}") diff --git a/utils/template_filters.py b/utils/template_filters.py index c31b585..7c61d49 100644 --- a/utils/template_filters.py +++ b/utils/template_filters.py @@ -15,6 +15,7 @@ from little_boxes.activitypub import _to_list from little_boxes.errors import ActivityGoneError from little_boxes.errors import ActivityNotFoundError +from config import BASE_URL from config import EMOJI_TPL from config import ID from config import MEDIA_CACHE @@ -249,6 +250,8 @@ def _get_file_url(url, size, kind) -> str: # MEDIA_CACHE.cache(url, kind) _logger.error(f"cache not available for {url}/{size}/{kind}") + if url.startswith(BASE_URL): + return url return f"/p/{url}"