codec
import std::net::http2::codec; · source
Header-block coding for an HTTP/2 connection. A connection turns each request's or response's header list into a header block and back through a HeaderCodec. HpackCodec, RFC 7541's HPACK, is the one every connection uses unless it is built with another: Http2Connection<S> is Http2Connection<S, HpackCodec>, and Http2Connection<S, MyCodec> codes its header blocks with MyCodec. Both ends of a connection must code the same way, so a codec other than HPACK is for a peer that speaks it.
Types
HeaderField
type struct HeaderField {
name: String;
value: String;
}
One header field, owning its name and value bytes. new copies both as given — no case folding and no validation.
Properties
| Property | Type |
|---|---|
name | String |
value | String |
Constructors
static new(name: Str, value: Str) -> HeaderField;
static new(name: Str, value: Str) -> HeaderField;A field holding copies of name and value, both as given: no case folding and no validation.
HeaderCodec
type trait HeaderCodec {
encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> void;
decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>;
limit_encoder_table(mut &this, size: i64) -> void;
}
How a connection writes and reads header blocks. A codec may keep state across the blocks of one connection, as HPACK's tables do; it sees every block of one direction in order. A sensitive field passed to encode_field carries a credential: a codec that remembers fields for later blocks must not remember this one, and must tell whatever relays the block not to either. decode returns None for a block that is malformed or decodes past what the codec accepts. limit_encoder_table passes on the peer's SETTINGS_HEADER_TABLE_SIZE; a codec that stores nothing ignores it.
Methods
encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> void;
encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> void;Append the encoding of the field name: value to out. A sensitive field carries a credential: a codec that remembers fields for later blocks must not remember this one, and must tell whatever relays the block not to either.
decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>;
decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>;The fields block encodes, in order, or none when it is malformed or decodes past what the codec accepts.
limit_encoder_table(mut &this, size: i64) -> void;
limit_encoder_table(mut &this, size: i64) -> void;The most the peer's decoder stores, as its SETTINGS_HEADER_TABLE_SIZE says. A codec that stores nothing ignores it.
Implementors
implement trait HeaderCodec for struct HpackCodec
HpackCodec
type struct HpackCodec {
private encoder: HpackEncoder;
private decoder: HpackDecoder;
}
HPACK: an encoder and a decoder, each with its own dynamic table. new(table_size) bounds the decoder's table at table_size octets, as the connection advertises it, and starts the encoder at the same size until the peer's SETTINGS says otherwise. The HPACK and Huffman coders behind it are internal to the standard library.
Constructors
static new(table_size: i64) -> HpackCodec;
static new(table_size: i64) -> HpackCodec;A codec whose own decoder table holds at most table_size octets, as the connection advertises it, and whose encoder starts at the same size until the peer's SETTINGS says otherwise.
Trait implementations
implement trait HeaderCodec for struct HpackCodec
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 HeaderField {
name: String;
value: String;
}One header field. Owns its name and value bytes.
HeaderField.name: Stringtype struct String<A = GlobalAllocator> {}Owned, growable UTF-8 text. It dereferences to Str, the read-only view most text functions take, so every Str method reads a String too (s.contains(...), s.split(...)); as_str hands the view out.
HeaderField.value: Stringtype trait Name : Base {
method(&this, other: &This) -> Ret;
}Names a set of methods a type may implement. Inside the body This is the implementing type; methods may carry default bodies, and a trait may require a base trait (type trait Ord : Eq). Generic code asks for a trait with where T: Name.
type trait HeaderCodec {
encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> void;
decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>;
limit_encoder_table(mut &this, size: i64) -> void;
}How a connection writes and reads header blocks. A codec may keep state across the blocks of one connection, as HPACK's tables do; it sees every block of one direction in order.
HeaderCodec::encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> voidAppend the encoding of the field name: value to out. A sensitive field carries a credential: a codec that remembers fields for later blocks must not remember this one, and must tell whatever relays the block not to either.
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.
&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.
(parameter) out: mut &Array<u8>type struct Array<T, A = GlobalAllocator> where A: Allocator {}A growable sequence of Ts stored contiguously, owning its elements; A is the allocator its storage comes from. Indexing out of range panics; get answers None instead.
(parameter) name: Strtype struct Str {}A read-only view of UTF-8 text owned elsewhere: a string literal, a String, a file's bytes. Copying a Str copies the view, not the text, and it is valid only while what it views is. Str::new("text") views a literal; String.as_str() views a String.
(parameter) value: Str(parameter) sensitive: booleanHeaderCodec::decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>The fields block encodes, in order, or none when it is malformed or decodes past what the codec accepts.
(parameter) block: &Slice<u8>type struct Slice<T> {}The elements are reached through ptr, declared read-only: through a mut &Slice<T> it reads as a writable pointer, through a &Slice<T> as the read-only one it is.
type enum Option<T> with [Eq, Clone, Debug] {
Some(T);
None;
}A value of type T that may be absent: Some(value) or None.
type struct HeaderField {
name: String;
value: String;
}One header field. Owns its name and value bytes.
std::net::http2::codecHeaderCodec::limit_encoder_table(mut &this, size: i64) -> voidThe most the peer's decoder stores, as its SETTINGS_HEADER_TABLE_SIZE says. A codec that stores nothing ignores it.
(parameter) size: i64type struct HpackCodec {}HPACK (RFC 7541): an encoder and a decoder, each with its own dynamic table.
private type struct Name { ... }
private:Confined to the module that declares it - for items and members alike. A private field or function reached from another module is E0353, and a private type named there is E0503. private: opens a block of such members.
HpackCodec.encoder: HpackEncoderHpackCodec.decoder: HpackDecoderimport 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).
namespace std::net::http2;net::http2: HTTP/2 (RFC 7540) with HPACK header compression (RFC 7541).
module pagetype trait HeaderCodec {
encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> void;
decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>;
limit_encoder_table(mut &this, size: i64) -> void;
}How a connection writes and reads header blocks. A codec may keep state across the blocks of one connection, as HPACK's tables do; it sees every block of one direction in order.
std::net::http2::codectype struct HpackCodec {}HPACK (RFC 7541): an encoder and a decoder, each with its own dynamic table.
std::net::http2::codectype struct Http2Connection<S, C = HpackCodec> where C: HeaderCodec {}One HTTP/2 connection over the transport S, coding header blocks with C. It owns the buffered transport and the protocol state: the header codec's tables, the peer's frame size and initial window, the send windows and the next stream identifier.
new T { field: value }
new Path(args)
new E::Variant
new T[n]Heap allocation. new T { .. } places a struct literal on the heap and yields a T*, and new E::V does the same for a unit variant. new Path(args) places the value a call returns, whatever its type: new Table::new(8), new Option<i64>::Some(41), new make_pair(3, 4). new T[n] reserves n uninitialised T - the typed malloc. The storage comes from the value type's Allocate implementation, or else the global allocator. A type is not a function, so new Point(1, 2) is refused (E0231).
HeaderField.name: StringHeaderField.value: 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 HeaderField::new(name: Str, value: Str) -> HeaderFieldA field holding copies of name and value, both as given: no case folding and no validation.
HeaderCodec::encode_field(mut &this, out: mut &Array<u8>, name: Str, value: Str, sensitive: boolean) -> voidAppend the encoding of the field name: value to out. A sensitive field carries a credential: a codec that remembers fields for later blocks must not remember this one, and must tell whatever relays the block not to either.
HeaderCodec::decode(mut &this, block: &Slice<u8>) -> Option<Array<HeaderField>>The fields block encodes, in order, or none when it is malformed or decodes past what the codec accepts.
Option::NoneHeaderCodec::limit_encoder_table(mut &this, size: i64) -> voidThe most the peer's decoder stores, as its SETTINGS_HEADER_TABLE_SIZE says. A codec that stores nothing ignores it.
std::net::http2::codecimplement 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(parameter) table_size: i64