Skip to main content

HttpClient

Trait HttpClient 

Source
pub trait HttpClient:
    Send
    + Sync
    + 'static {
    // Required method
    fn send(
        &self,
        request: &HttpRequest,
        body_limit: u64,
    ) -> Result<HttpResponse, String>;
}
Expand description

The transport a script’s HTTP builtins run on.

Implementations are called from a per-request worker thread and may block for the length of the request, so they must not touch the world.

Required Methods§

Source

fn send( &self, request: &HttpRequest, body_limit: u64, ) -> Result<HttpResponse, String>

Perform request and return the reply.

Err is reserved for transport failures (DNS, connect, TLS, timeout, a malformed method or url); any status that came back over the wire is Ok. The error string reaches the script verbatim as the reply’s error field, so it should read as a sentence.

body_limit is a hard cap, in bytes, on the response body buffered into memory. Reading past it must fail rather than allocate: an open-ended or streaming endpoint must not be able to exhaust memory on the worker thread.

Implementors§