headers
import std::net::http::headers; · source
Types
Headers
type struct Headers {
inner: HashMap<String, String>;
static new() -> Headers;
length(&this) -> u64;
is_empty(&this) -> boolean;
insert(mut &this, name: Str, value: Str) -> void;
get(&this, name: Str) -> Option<String>;
contains(&this, name: Str) -> boolean;
remove(mut &this, name: Str) -> boolean;
parse_line(mut &this, line: Str) -> boolean;
content_length(&this) -> Result<Option<u64>, IoError>;
encode_into(&this, out: Array<u8>*) -> Result<(), IoError>;
}
A case-insensitive map: names are lower-cased on the way in, so get finds a header however the peer spelled it. get returns an owned copy. encode_into(out) serializes every header as name: value\r\n; parse_line consumes one name: value line, returning false if it is malformed.
content_length() returns Result<Option<u64>, IoError> — absent is Ok(None), malformed is an error.
Properties
| Property | Type |
|---|---|
inner | HashMap<String, String> |
Constructors
static new() -> Headers;
Methods
length(&this) -> u64;
is_empty(&this) -> boolean;
insert(mut &this, name: Str, value: Str) -> void;
insert(mut &this, name: Str, value: Str) -> void;Insert or replace. Name is normalized to lowercase; CR/LF bytes are stripped from both name and value before storing. Ownership of both values transfers to the headers map.
get(&this, name: Str) -> Option<String>;
get(&this, name: Str) -> Option<String>;Case-insensitive lookup. Returns a deep-cloned owned copy of the stored value (header values are small, so copy-on-read is cheap), so the caller owns it independently of the map and must drop it.
contains(&this, name: Str) -> boolean;
remove(mut &this, name: Str) -> boolean;
parse_line(mut &this, line: Str) -> boolean;
parse_line(mut &this, line: Str) -> boolean;Parse a single Name: Value header line (no CRLF). Used by the request parser. Returns None on malformed input; the caller turns that into a 400.
content_length(&this) -> Result<Option<u64>, IoError>;
content_length(&this) -> Result<Option<u64>, IoError>;Content-Length as a number. Ok(None) means the header is absent, which for this parser means "no body". A present but non-numeric value is InvalidData rather than a silent None: a peer that sends Content-Length: abc has framed the message wrongly, and guessing at zero would leave its body bytes in the buffer to be read as the next message.
encode_into(&this, out: Array<u8>*) -> Result<(), IoError>;
encode_into(&this, out: Array<u8>*) -> Result<(), IoError>;Append every stored header to out as HTTP/1.1 field lines, name: value\r\n per entry. The caller appends the trailing blank-line CRLF that separates headers from the message body.
Trait implementations
implement trait Drop for struct Headers
type struct Name { ... }
type enum Name { ... }
type trait Name { ... }
type union Name { ... }Begins a type declaration; the keyword that follows says which kind. On its own, type Name = Existing; declares an alias.
type struct Name {
field: Type;
method(&this) -> Ret { ... }
}A value type with named fields and optional methods. Structs live on the stack and are passed by value. Fields are public by default and may carry = default values; methods take their receiver as &this, mut &this, or this.
type struct Headers {
inner: HashMap<String, String>;
}HTTP headers: case-insensitive name/value map.
Headers.inner: HashMap<String, String>type struct HashMap<K, V, A = GlobalAlloc> where A: Allocator {
buckets: Entry<K, V>**;
bucket_count: u64;
length: u64;
alloc: A;
seed: u64;
}HashMap<K, V, A>: key-value map with amortized O(1) operations.
std::collections::hashmaptype struct String<A = GlobalAlloc> {
buffer: RawBuffer<u8, A>;
length: u64;
}String: owned, heap-allocated, length-typed UTF-8.
std::collections::stringstatic name(param: Type) -> Ret { ... }A method that belongs to the type rather than an instance, called as Type::name(..). For structs, static new(..) returning a struct literal is the idiomatic constructor.
static Headers::new() -> Headerstype struct Headers {
inner: HashMap<String, String>;
}HTTP headers: case-insensitive name/value map.
std::net::http::headersHeaders::length(&this) -> u64&this
mut &this
thisThe receiver of a method. Its first parameter declares how the method takes it: &this borrows read-only, mut &this borrows exclusively, and this / mut this move the value in and consume it. In the body, this.field reaches the members.
Headers::is_empty(&this) -> booleanHeaders::insert(mut &this, name: Str, value: Str) -> voidInsert or replace. Name is normalized to lowercase; CR/LF bytes are stripped from both name and value before storing. Ownership of both values transfers to the headers map.
mut &this
mut &TypeAn exclusive, mutating borrow. As a receiver, mut &this lets the method modify the fields - and callers can see that from the signature alone. As a parameter type, mut &T lets the callee mutate through the reference while the caller keeps ownership.
(parameter) name: Strtype struct Str {
bytes: u8*;
length: u64;
}Str: a borrowed UTF-8 string slice.
std::collections::str(parameter) value: StrHeaders::get(&this, name: Str) -> Option<String>Case-insensitive lookup. Returns a deep-cloned owned copy of the stored value (header values are small, so copy-on-read is cheap), so the caller owns it independently of the map and must drop it.
Headers::contains(&this, name: Str) -> booleanHeaders::remove(mut &this, name: Str) -> booleanHeaders::parse_line(mut &this, line: Str) -> booleanParse a single Name: Value header line (no CRLF). Used by the request parser. Returns None on malformed input; the caller turns that into a 400.
(parameter) line: StrHeaders::content_length(&this) -> Result<Option<u64>, IoError>Content-Length as a number. Ok(None) means the header is absent, which for this parser means "no body".
type struct IoError {
kind: IoErrorKind;
os_code: i32;
}Headers::encode_into(&this, out: Array<u8>*) -> Result<(), IoError>Append every stored header to out as HTTP/1.1 field lines, name: value\r\n per entry. The caller appends the trailing blank-line CRLF that separates headers from the message body.
(parameter) out: Array<u8>*type struct Array<T, A = GlobalAlloc> where A: Allocator {
ptr: T*;
length: i64;
capacity: i64;
alloc: A;
}Array<T, A>: growable, heap-backed, contiguous sequence.
std::collections::arrayprimitive ()The unit type: a value that carries no information, and the empty tuple. Distinct from void, which is the absence of a value - Result<(), E> succeeds with nothing to return. 0 bytes.
import a::b;
import a::b::{ X, Y };
import a::b as c;
import a::b::*;Brings a module, or selected items from it, into scope. One path per declaration: use the brace form for several items, as to alias, and * for everything public (prefer the brace form; wildcards invite name collisions).
Headers::get(&this, name: Str) -> Option<String>Case-insensitive lookup. Returns a deep-cloned owned copy of the stored value (header values are small, so copy-on-read is cheap), so the caller owns it independently of the map and must drop it.
std::net::http::headersHeaders::encode_into(&this, out: Array<u8>*) -> Result<(), IoError>Append every stored header to out as HTTP/1.1 field lines, name: value\r\n per entry. The caller appends the trailing blank-line CRLF that separates headers from the message body.
Headers::parse_line(mut &this, line: Str) -> booleanParse a single Name: Value header line (no CRLF). Used by the request parser. Returns None on malformed input; the caller turns that into a 400.
falseThe boolean literal. Booleans are a distinct 1-byte type, not interchangeable with integers; if and while conditions must be boolean.
Headers::content_length(&this) -> Result<Option<u64>, IoError>Content-Length as a number. Ok(None) means the header is absent, which for this parser means "no body".
Result::Ok(T)Option::NoneHeaders.inner: HashMap<String, String>static Headers::new() -> HeadersHeaders::length(&this) -> u64Headers::is_empty(&this) -> booleanHeaders::insert(mut &this, name: Str, value: Str) -> voidInsert or replace. Name is normalized to lowercase; CR/LF bytes are stripped from both name and value before storing. Ownership of both values transfers to the headers map.
std::net::http::headersHeaders::contains(&this, name: Str) -> booleanHeaders::remove(mut &this, name: Str) -> booleanIoErrorKind::InvalidDataimplement struct Name { ... }
implement trait Trait for Type { ... }
implement u64 { ... }Adds methods to a type outside its declaration. implement struct T (or enum, or a bare primitive) opens an inherent block; implement trait Tr for T supplies a trait's methods for one type. Resolution is at compile time - no dynamic dispatch.
implement trait Trait for Type { ... }Introduces a trait implementation: the block supplies, for one concrete type, the method bodies the trait requires.
language referenceimplement trait Trait for Type { ... }Names the type a trait implementation is for. The block that follows supplies the bodies the trait requires.
language reference