Stdlibnet::http
request
import std::net::http::request; · source
Request
type struct Request {
method: Method;
path: String;
version: String;
headers: Headers;
body: Array<u8>;
params: HashMap<String, String>;
static new(method: Method, path: Str) -> Request;
param(&this, name: Str) -> Option<String>;
with_header(mut this, name: Str, value: Str) -> Request;
with_body(mut this, body: Array<u8>) -> Request;
set_body(mut &this, body: Array<u8>) -> void;
static from_request_line(line: Str) -> Result<Request, IoError>;
encode_into(&this, out: Array<u8>*) -> Result<(), IoError>;
}
const HTTP_VERSION: Str = Str::new("HTTP/1.1");
const MAX_HEADER_LINE: u64 = 8192;
const MAX_BODY: u64 = 16777216;
Request::new(method, path) builds one; with_header(name, value) and with_body(body) consume and return it so they chain, and set_body(body) mutates in place. param(name) reads a router capture. encode_into(out) writes the complete HTTP/1.1 message — request line, headers, blank line, body.
mut req: Request = Request::new(Method::Post, Str::new("/api/items"))
.with_header(Str::new("Content-Type"), Str::new("application/json"))
.with_body(body);
from_request_line parses the first line of an incoming request; the header and body reads that follow it live in conn. The fields are public, so a handler can read req.headers or req.body directly. MAX_HEADER_LINE and MAX_BODY bound what a reader will accept.
Trait implementations
implement trait Drop for struct Request