Import with #import "std/net_http".

HttpHeader :: struct { name: string; value: string; }

Network transport is an explicit host capability. The host adds a Bearer Authorization header when token is nonempty. It must not log that token. The request and response records have the same meaning in native targets and portable bundles.

HttpRequest :: struct { method: string; url: string; token: string; accept: string; content_type: string; body: string; headers: []HttpHeader; }
HttpResponse :: struct { status: s32; body: string; error: string; }
HttpInputFailure :: enum { None = 0; InvalidLimit = 1; InvalidUrl = 2; HostError = 3; TooLarge = 4; }
HttpTextValid :: (text: string) -> bool
Send :: (request: HttpRequest) -> HttpResponse

Needs a host capability.

HttpUrlValid :: (url: string) -> bool
ValidateHttpRequest :: (request: HttpRequest, maximum_body: s64) -> Result(HttpRequest, HttpInputFailure)
ValidateHostResponse :: (response: HttpResponse, maximum_body: s64) -> Result(HttpResponse, HttpInputFailure)
SendCapped :: (request: HttpRequest, maximum_body: s64) -> Result(HttpResponse, HttpInputFailure)

The host result is accepted only after URL validation and the caller's cap.

Needs a host capability.

Source ↗ · All modules