aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/net.py12
-rw-r--r--webmentions_ssg/tasks/discovery.py3
-rw-r--r--webmentions_ssg/tasks/receiver.py5
3 files changed, 16 insertions, 4 deletions
diff --git a/webmentions_ssg/net.py b/webmentions_ssg/net.py
index 0314810..7c29edc 100644
--- a/webmentions_ssg/net.py
+++ b/webmentions_ssg/net.py
@@ -9,6 +9,7 @@ import socket
import time
from collections.abc import Iterable
from contextlib import ExitStack
+from http import HTTPStatus
from urllib.parse import urlsplit
import dns.exception
@@ -20,6 +21,7 @@ from httpcore._backends.sync import SyncStream
NAT64_PREFIX = ipaddress.IPv6Network("64:ff9b::/96")
IPV4_COMPATIBLE_PREFIX = ipaddress.IPv6Network("::/96")
+NETWORK_CONNECT_TIMOUT_ERROR = 599
class AddressResolutionError(Exception):
@@ -285,4 +287,12 @@ def read_limited_body(response: httpx.Response, max_bytes: int, *, label: str) -
def is_temporary_status(status: int) -> bool:
"""Return whether an HTTP status is normally retryable."""
- return status in {408, 425, 429} or 500 <= status <= 599
+ return (
+ status
+ in {
+ HTTPStatus.REQUEST_TIMEOUT,
+ HTTPStatus.TOO_EARLY,
+ HTTPStatus.TOO_MANY_REQUESTS,
+ }
+ or HTTPStatus.INTERNAL_SERVER_ERROR <= status <= NETWORK_CONNECT_TIMOUT_ERROR
+ )
diff --git a/webmentions_ssg/tasks/discovery.py b/webmentions_ssg/tasks/discovery.py
index 456e47e..107d30a 100644
--- a/webmentions_ssg/tasks/discovery.py
+++ b/webmentions_ssg/tasks/discovery.py
@@ -5,6 +5,7 @@
"""Discover a target Webmention endpoint and submit a POST."""
import re
+from http import HTTPStatus
from urllib.parse import urljoin
import httpx
@@ -198,7 +199,7 @@ def post_webmention(
) as response:
status_url = None
- if response.status_code == 201 and (
+ if response.status_code == HTTPStatus.CREATED and (
location := response.headers.get("Location")
):
try:
diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/receiver.py
index cbb42b6..78089af 100644
--- a/webmentions_ssg/tasks/receiver.py
+++ b/webmentions_ssg/tasks/receiver.py
@@ -6,6 +6,7 @@
import uuid
from datetime import UTC, datetime, timedelta
+from http import HTTPStatus
from typing import Any, cast
import httpx
@@ -62,9 +63,9 @@ def fetch_source(source_url: str) -> tuple[httpx.Response, bytes]:
) as client,
client.stream("GET", source_url) as response,
):
- if response.status_code == 200:
+ if response.status_code == HTTPStatus.OK:
pass
- elif response.status_code == 410:
+ elif response.status_code == HTTPStatus.GONE:
raise SourceGoneError("Source returned HTTP 410")
elif is_temporary_status(response.status_code):
raise TemporaryFetchError(