httk.serve.http.webhook¶
Hardened outbound HTTPS JSON webhook delivery.
This module is a general-purpose hardened outbound webhook client: strict HTTPS URL parsing (rejecting userinfo, query, fragment, control characters, and non-ASCII after IDNA), DNS resolution filtered to globally-routable addresses only, a connection pinned to a resolved numeric address with TLS SNI carrying the original logical hostname (a DNS-rebinding defence), a bounded HTTP/1.1 request and response cycle with header-size caps and Content-Length / chunked / close-delimited body framing, per-address retry, a concurrency semaphore, and layered connect/read/DNS/total timeouts.
It carries no protocol vocabulary. The Data Space Protocol consumes it through
httk.serve.dsp.callbacks, which retains the DSP-facing spelling of these
names.
Attributes¶
Exceptions¶
Represent an outbound webhook transport or URL-policy failure. |
Classes¶
Send one HTTPS JSON POST through a validated, pinned socket. |
Functions¶
|
Append a fixed absolute path without depending on a trailing slash. |
|
Deliver a document through a sender at most |
Module Contents¶
- type httk.serve.http.webhook.WebhookSender = Callable[[str, dict[str, JsonValue]], Awaitable[int]][source]¶
- exception httk.serve.http.webhook.WebhookTransportError(detail)[source]¶
Bases:
RuntimeErrorRepresent an outbound webhook transport or URL-policy failure.
- Parameters:
detail (str) – Safe detail suitable for local process-delivery state.
- httk.serve.http.webhook.join_url_path(base_url, path)[source]¶
Append a fixed absolute path without depending on a trailing slash.
- Parameters:
- Returns:
Complete URL.
- Raises:
ValueError – If the base or fixed path is malformed.
- Return type:
- class httk.serve.http.webhook.PinnedHttpsJsonPoster(*, connect_timeout=5.0, read_timeout=10.0, dns_timeout=5.0, total_timeout=20.0, response_body_limit=65536, max_concurrency=8, allow_private_addresses=False, resolver=None, connector=None)[source]¶
Send one HTTPS JSON POST through a validated, pinned socket.
DNS resolution occurs inside the concurrency cap and produces the exact numeric socket address dialed for the request. TLS SNI and the HTTP
Hostheader retain the original DNS hostname. The stdlib transport does not consult proxy or environment settings; redirects are not implemented. Both DNS and the complete operation have finite deadlines.- Parameters:
connect_timeout (float) – Maximum seconds for TCP connect and TLS handshake.
read_timeout (float) – Maximum seconds for reading a complete response body.
dns_timeout (float) – Maximum seconds for DNS resolution.
total_timeout (float) – Maximum seconds from the start of resolution through response completion.
response_body_limit (int) – Maximum response bytes consumed before rejection.
max_concurrency (int) – Maximum simultaneous resolution and send operations.
allow_private_addresses (bool) – Skip global-address filtering when
True; the default rejects private targets.resolver (_Resolver | None) – Optional test seam that resolves public pinned addresses.
connector (_Connector | None) – Optional test seam that dials a supplied pinned address.
- async httk.serve.http.webhook.deliver_with_retries(sender, url, document, *, attempts=2)[source]¶
Deliver a document through a sender at most
attemptstimes, requiring a 2xx status.- Parameters:
sender (WebhookSender) – Awaitable sender returning a peer HTTP status code.
url (str) – Complete webhook URL passed to the sender.
document (dict[str, httk.serve.jsondata.JsonValue]) – Plain JSON message document passed to the sender.
attempts (int) – Maximum number of delivery attempts before failing.
- Raises:
WebhookTransportError – If no attempt yields a 2xx acknowledgement.