HeaderMapView
struct HeaderMapView[origin: Origin[mut=origin.mut]]Borrowed header collection.
Holds offsets into a caller-owned byte buffer (self.buf)
plus a parallel List[Int] of (name_start, name_len, value_start, value_len) quadruples (4 ints per header).
Lookups are case-insensitive ASCII; comparison runs against the
underlying buf in place.
The origin parameter ties the view's lifetime to the
buffer it borrows from. Mojo's borrow checker prevents the
view from outliving the buffer.
Implements Movable
- Fields
buf: Span[UInt8, origin]: The byte buffer the view borrows from. TypicallyConnHandle.read_buffor the reactor read path; may be anySpan[UInt8, ...]for tests / WS handshake / future HTTP/2 HEADERS frame readers.
__init__
def __init__(out self, buf: Span[UInt8, origin]) Empty view bound to buf. Use parse_header_view to populate from raw header bytes.
def __init__(out self, buf: Span[UInt8, origin], var offsets: List[Int]) Populated view. len(offsets) must be a multiple of 4.
len
def len(self) -> Int Number of headers in the view.
get
def get(self, name: String) -> StringSpan[origin_of(origin)] Return the value of the first header named name, case-insensitive. Returns an empty slice if not present.
The returned slice borrows from self.buf; its lifetime
is tied to the view's origin. No allocation.
count
def count(self, name: String) -> Int Number of header lines named name, case-insensitive.
contains
def contains(self, name: String) -> Bool True if a header named name is present (case-insensitive).
into_owned
def into_owned(self) -> HeaderMap Materialise an owned HeaderMap by copying each header's bytes out of the borrowed buffer into Strings.
One allocation per header (key + value). Use this only when the handler needs to keep headers alive past the connection's event-loop iteration; the borrowed view itself does not allocate per header.