Skip to main content

Module net

Module net 

Source
Expand description

Network utilities — SSRF protection, HTTP client helpers.

Re-exports§

pub use reqwest;

Structs§

Egress
Where a request for url really goes, and what it carries: the proxy’s address with a signed authorization when the privacy setting routes it through Magnitude, or the URL itself.

Constants§

TRANSFER_STALL
How long a transfer may go without moving a byte before it is given up on.

Functions§

build_http_client
Build an HTTP client with the given total timeout.
build_http_client_with_options
egress
Resolve the destination for url. Every outbound fetch of somebody else’s content asks here first, so the setting has exactly one place to act.
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.
proxied_request
A request for url on client, already pointed at the right place and carrying the proxy authorization when there is one.
raise_fd_limit
Lift the open-file ceiling to what the OS allows.
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.
remote_status
The HTTP status the SOURCE gives for url: 2xx means it serves, 404/410 means it is gone. None means nothing definitive could be learned (the host, or the proxy, was unreachable). Through the proxy a HEAD carries no body, so one byte is asked for instead and the source’s status read from the proxy’s answer; direct, a HEAD is tried first and a one-byte GET when the host refuses HEAD.
set_app_version
Name the app’s version in the user agent. Call once at startup; a second call is ignored.
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.
user_agent
validate_url_not_private
Reject URLs that resolve to private/loopback/link-local addresses (SSRF protection).