Stdlibnet::http
response
import std::net::http::response; · source
Response
type struct Response {
status: StatusCode;
version: String;
headers: Headers;
body: Array<u8>;
static new(status: StatusCode) -> Response;
static text(status: StatusCode, body: Str) -> Response;
static json(status: StatusCode, body: Array<u8>) -> Response;
set_body(mut &this, body: Array<u8>) -> void;
static from_status_line(line: Str) -> Result<Response, IoError>;
encode_into(&this, out: Array<u8>*) -> Result<(), IoError>;
}
const MAX_BODY: u64 = 16777216;
const MAX_HEADER_COUNT: u64 = 100;
Response::new(status) is the bare form; Response::text(status, body) and Response::json(status, body) set the body and the matching Content-Type. set_body installs a body and sets Content-Length to match; encode_into(out) writes the complete HTTP/1.1 message.
function health(req: Request) -> Response {
return Response::text(StatusCode::ok(), Str::new("ok"));
}
from_status_line parses the first line of an incoming response; the header and body reads that follow it live in conn. MAX_BODY is the hard cap against a runaway or attacker-controlled Content-Length, and MAX_HEADER_COUNT bounds the header block.
Trait implementations
implement trait Drop for struct Response