diff options
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/net.py | 12 |
1 files changed, 11 insertions, 1 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 + ) |
