Skip to main content

Module net

Module net 

Source
Expand description

Network utilities — SSRF protection, HTTP client helpers.

Functions§

build_http_client
Build an HTTP client with the given timeout.
build_http_client_with_options
Like build_http_client, optionally without redirect-following. Blossom PUT uses false: a 3xx mid-upload would re-issue as GET and drop the body, so we surface the 3xx as the real failure status.
get_remote_file_size
Get the size of a remote file via HEAD request or Range fallback. Returns None if the URL is private, unreachable, or size can’t be determined.
rebuild_shared_http_client
Rebuild the shared client. Call this when Tor state flips so the next request goes through the freshly-configured proxy. In-flight requests on the old client continue to completion on the previous Arc.
shared_http_client
Get a shared HTTP client. Cheap clone (Arc), proxy-aware, picks up Tor toggles on the next call after rebuild_shared_http_client() runs.
strip_md_link_claims
Rewrite markdown links so a preview-URL scan sees only real DESTINATIONS: [text](href) keeps the href and drops the display text — a URL claimed in the text must never win the OG preview over where the link actually goes — [text](<href>) drops entirely (angle brackets are the no-preview syntax), and [text][ref] drops the label (its destination is a definition scanned on its own elsewhere in the text). Images (![alt](url)) render as literal text in chat, so they pass through untouched.
validate_url_not_private
Reject URLs that resolve to private/loopback/link-local addresses (SSRF protection).