messua/ok
Helpers for building responses.
All body-adding functions set an appropriate Content-Type
header unless otherwise noted.
You shouldn’t need to set the Content-Length
header; that’ll
get set automatically when necessary.
Functions
pub fn compress_body(
resp: Response(ResponseData),
) -> Response(ResponseData)
Compress a response body using deflate
.
This sets the Content-Encoding header, but you should still make sure a Content-Type has been set.
pub fn with_binary_body(
resp: Response(ResponseData),
body: BytesBuilder,
) -> Response(ResponseData)
Add a body of raw bytes.
This sets the Content-Type to application/octet-stream
; use
with_header()
if you want a different Content-Type.
pub fn with_header(
resp: Response(ResponseData),
name: String,
value: String,
) -> Response(ResponseData)
Add the given header to the response.
pub fn with_json_body(
resp: Response(ResponseData),
body: Json,
) -> Response(ResponseData)
Add a Json
body (as produced by the gleam_json
package).
pub fn with_text_body(
resp: Response(ResponseData),
body: String,
) -> Response(ResponseData)
Add a plain-text body.