Fix proxy

This commit is contained in:
Thomas Sileo 2019-08-18 11:48:18 +02:00
parent 3aefaff818
commit 8613cc0206
2 changed files with 5 additions and 0 deletions

2
app.py
View file

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

View file

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