Http module

bytes_response

procedureextensionexperimentalSource

Raw bytes (a [] u8 or a string) with a content type of your choice. The bytes must stay valid until the response is written.

Example
response := bytes_response(u8.[137, 80, 78, 71], "image/png");
assert(response.body.count == 4);
type, _ := find_header(response.headers, "Content-Type");
assert(type == "image/png");

Doesn't run in the browser (skipped on wasm).

bytes_response :: (body: $T, content_type: string, status := 200) -> Response

Raw bytes (a [] u8 or a string) with a content type of your choice. The bytes must stay valid until the response is written.

Parameters

body: $T
a [] u8 or a string, sent as it is.
content_type: string
the Content-Type header value.
status := 200
the HTTP status code.

Returns

Example
response := bytes_response(u8.[137, 80, 78, 71], "image/png");
assert(response.body.count == 4);
type, _ := find_header(response.headers, "Content-Type");
assert(type == "image/png");

Doesn't run in the browser (skipped on wasm).

See also