mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-11-15 03:04:28 +00:00
Tweak lookup
This commit is contained in:
parent
b42f82acde
commit
5bc655dfd3
1 changed files with 13 additions and 6 deletions
|
@ -4,6 +4,7 @@ import little_boxes.activitypub as ap
|
||||||
import mf2py
|
import mf2py
|
||||||
import requests
|
import requests
|
||||||
from little_boxes.errors import NotAnActivityError
|
from little_boxes.errors import NotAnActivityError
|
||||||
|
from little_boxes.errors import RemoteServerUnavailableError
|
||||||
from little_boxes.webfinger import get_actor_url
|
from little_boxes.webfinger import get_actor_url
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,14 +21,20 @@ def lookup(url: str) -> ap.BaseActivity:
|
||||||
# Some websites may returns 404, 503 or others when they don't support webfinger, and we're just taking a guess
|
# Some websites may returns 404, 503 or others when they don't support webfinger, and we're just taking a guess
|
||||||
# when performing the lookup.
|
# when performing the lookup.
|
||||||
pass
|
pass
|
||||||
|
except requests.RequestException as err:
|
||||||
|
raise RemoteServerUnavailableError(f"failed to fetch {url}: {err!r}")
|
||||||
|
|
||||||
backend = ap.get_backend()
|
backend = ap.get_backend()
|
||||||
resp = requests.get(
|
try:
|
||||||
|
resp = requests.head(
|
||||||
url,
|
url,
|
||||||
timeout=15,
|
timeout=10,
|
||||||
allow_redirects=False,
|
allow_redirects=True,
|
||||||
headers={"User-Agent": backend.user_agent()},
|
headers={"User-Agent": backend.user_agent()},
|
||||||
)
|
)
|
||||||
|
except requests.RequestException as err:
|
||||||
|
raise RemoteServerUnavailableError(f"failed to GET {url}: {err!r}")
|
||||||
|
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
|
|
||||||
# If the page is HTML, maybe it contains an alternate link pointing to an AP object
|
# If the page is HTML, maybe it contains an alternate link pointing to an AP object
|
||||||
|
|
Loading…
Reference in a new issue