pub struct OwnedRequestHead { /* private fields */ }Expand description
A request head that owns its bytes and spans: from
RequestHead::to_owned, or rebuilt from a passport’s parts with
from_parts. Debug shows the head the way
RequestHead does, credential values redacted.
§Examples
See RequestHead::to_owned and HeadFacts.
Implementations§
Source§impl OwnedRequestHead
impl OwnedRequestHead
Sourcepub fn view(&self) -> RequestHead<'_>
pub fn view(&self) -> RequestHead<'_>
A view of the owned head, with every accessor of a borrowed one.
§Examples
Sourcepub fn from_parts(
bytes: Vec<u8>,
fields: Vec<FieldSpan>,
facts: HeadFacts,
) -> Result<Self, HttpError>
pub fn from_parts( bytes: Vec<u8>, fields: Vec<FieldSpan>, facts: HeadFacts, ) -> Result<Self, HttpError>
Rebuilds an owned head from copied parts (RequestHead::copy_into),
checking first that they still describe one head: every span lies
inside bytes, the start line and every field line have the
structure the parser accepted (method, target, and version where the
facts say, each field name a token followed by a colon, each value
without control bytes or surrounding whitespace, the lines in order
and back to back, the blank line last), and the host and target
spans in the facts point where they should. A passport whose
structure was changed is refused, never read. The check is
structural, not an integrity check: a change that keeps every rule (a
different target, Host, or field value of valid bytes) is accepted,
so a passport that crosses a trust boundary needs its own MAC.
The framing facts themselves (body length, keep-alive) are taken as given: they come from the same trusted copy, and recomputing them would be the parse this is meant to avoid.
§Errors
HttpError::InvalidState, naming the first rule that failed.
§Examples
use http_net::{HttpError, OwnedRequestHead, ServerConn, ServerEvent};
let mut conn = ServerConn::new();
let _ = conn.feed(b"GET / HTTP/1.1\r\nHost: a\r\n\r\n");
let ServerEvent::Request(req) = conn.poll().unwrap() else { panic!() };
let (mut bytes, mut fields) = (Vec::new(), Vec::new());
let facts = req.copy_into(&mut bytes, &mut fields)?;
bytes[16] = b' '; // the first field name now starts with a space
assert!(matches!(
OwnedRequestHead::from_parts(bytes, fields, facts),
Err(HttpError::InvalidState(_))
));Sourcepub fn into_parts(self) -> (Vec<u8>, Vec<FieldSpan>, HeadFacts)
pub fn into_parts(self) -> (Vec<u8>, Vec<FieldSpan>, HeadFacts)
Gives the parts back, so a passport pool can reuse the vectors for the next head without allocating.
§Examples
use http_net::{ServerConn, ServerEvent};
let mut conn = ServerConn::new();
let _ = conn.feed(b"GET /a HTTP/1.1\r\nHost: a\r\n\r\n");
let ServerEvent::Request(req) = conn.poll().unwrap() else { panic!() };
let (mut bytes, mut fields, _facts) = req.to_owned().into_parts();
let capacity = bytes.capacity();
bytes.clear();
fields.clear();
assert_eq!(bytes.capacity(), capacity);