RequestView
struct RequestView[origin: Origin[mut=origin.mut]]Borrowed HTTP request.
Stores one Span[UInt8, origin] (the underlying buffer)
plus offset-and-length pairs for the URL, body, and the
individual headers. Per-field accessors (url(),
body(), header(name)) reconstruct the borrowed slice
on demand from the buffer. This avoids Mojo's borrow-checker
rejection of "two [origin]-tied fields aliasing the same
memory" that a flatter design (one StringSlice for URL +
one Span for body + one HeaderMapView for headers)
triggers.
Fields:
method: ASCII method token ("GET", "POST",
...). Owned String.
version: HTTP version ("HTTP/1.1"). Owned.
peer: Kernel-reported peer SocketAddr.
expose_errors: Whether 4xx response bodies may echo
handler-error messages.
buf: Underlying byte buffer borrowed from the
caller (typically ConnHandle.read_buf).
url_start / url_len: Byte range of the request URL
within buf.
body_start / body_len: Byte range of the request body
within buf.
header_offsets: Flat List[Int] of stride 4
(name_start, name_len, value_start,
value_len) — the same shape
HeaderMapView uses internally.
Implements Movable
- Fields
method: Stringversion: Stringpeer: SocketAddrexpose_errors: Boolbuf: Span[UInt8, origin]url_start: Inturl_len: Intbody_start: Intbody_len: Intheader_offsets: List[Int]
__init__
def __init__(out self, method: String, version: String, peer: SocketAddr, expose_errors: Bool, buf: Span[UInt8, origin], url_start: Int, url_len: Int, body_start: Int, body_len: Int, var header_offsets: List[Int]) url
def url(self) -> StringSpan[origin_of(origin)] Borrowed URL slice.
body
def body(self) -> Span[UInt8, origin] Borrowed body slice.
headers
def headers(self) -> HeaderMapView[origin] Build a HeaderMapView over this view's headers.
Cheap: copies the offsets list (typically a few ints) and
re-binds the buffer span. The returned view shares the
same origin.
into_owned
def into_owned(self) -> Request Materialise a Request whose fields are owned copies of the borrowed bytes.
Use when a handler needs to keep request state past one
event-loop iteration (background work, audit logging,
cross-request bookkeeping). Allocates: one String for
the URL, one HeaderMap worth of headers, one
List[UInt8] for the body.