Skip to content
CryoCryo home
Stdlibnet::http

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

PropertyType
innerHashMap<String, String>

Constructors

static new() -> Headers;

Methods

length(&this) -> u64;
is_empty(&this) -> boolean;
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>;

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 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 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>;

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