Expand description
Network utilities — SSRF protection, HTTP client helpers.
Re-exports§
Structs§
- Egress
- Where a request for
urlreally 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. - Http
Client - Req
- A request being built. Forwards the builder methods call sites use.
- Resp
- A response whose body reads stop when the network it came over changes.
Enums§
Constants§
- TRANSFER_
STALL - How long a transfer may go without moving a byte before it is given up on.
Functions§
- build_
http_ client - A client with the given total timeout, for content anyone can name.
- build_
http_ client_ for - A client for
lane:Accountfor requests that identify as the user (signed uploads). - build_
http_ client_ with_ options - Like
build_http_client, with the total timeout optional and redirect-following switchable. - 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. - forget_
clients - Drop every pooled client: the next request builds one for the current egress.
- 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.
- guard_
body - Upload bodies: ends the stream with an error when the epoch or live session changes.
- proxied_
request - A request for
urlonclient, 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 - Kept for callers that rebuilt the shared client on a Tor flip; clients are per request now.
- remote_
status - The HTTP status the SOURCE gives for
url: 2xx means it serves, 404/410 means it is gone.Nonemeans 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 - A 30 s client for frequent small fetches (image cache, wallet polling).
- 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 () render as literal text in chat, so they pass through untouched. - tor_
http_ timeout - An HTTP budget (a request total, a read) for the transport in use: a circuit to a fresh host alone can take 45 s. Clearnet passes through.
- transfer_
stall TRANSFER_STALLfor the transport in use.- user_
agent - validate_
url_ not_ private - Reject URLs that resolve to private/loopback/link-local addresses (SSRF protection).
- wait_
after - Hold a transfer that hit a network change until the network is back, then let it resume. Policy refusals and other failures return at once with their text.
Type Aliases§
- Body
Stream - A response body as a stream;
Sendnatively, where the browser’s isn’t.