pub struct ResponseReader { /* private fields */ }Expand description
Sans-IO HTTP/1.x response parser.
§Usage
use nexus_web::http::ResponseReader;
let mut reader = ResponseReader::new(4096);
reader.read(b"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\n\r\n").unwrap();
let resp = reader.next().unwrap().unwrap();
assert_eq!(resp.status, 101);
assert_eq!(resp.header("Upgrade"), Some("websocket"));Implementations§
Source§impl ResponseReader
impl ResponseReader
Sourcepub fn max_headers(self, n: usize) -> Self
pub fn max_headers(self, n: usize) -> Self
Set maximum number of headers. Default: 64.
Sourcepub fn max_head_size(self, n: usize) -> Self
pub fn max_head_size(self, n: usize) -> Self
Set maximum head size. Default: 8KB.
Sourcepub fn max_body_size(self, n: usize) -> Self
pub fn max_body_size(self, n: usize) -> Self
Set maximum response body size. Default: 0 (no limit).
When set, responses with Content-Length exceeding this value will be rejected during validation.
Sourcepub fn max_body_size_limit(&self) -> usize
pub fn max_body_size_limit(&self) -> usize
Configured maximum body size (0 = no limit).
Sourcepub fn spare(&mut self) -> &mut [u8] ⓘ
pub fn spare(&mut self) -> &mut [u8] ⓘ
Writable region for direct in-buffer writes. Pair with
filled() to commit bytes after the write.
Used by crate::WireStream to deliver bytes from a transport
without a slice intermediate.
Sourcepub fn read_from<R: Read>(&mut self, src: &mut R) -> Result<usize>
pub fn read_from<R: Read>(&mut self, src: &mut R) -> Result<usize>
Read bytes from a source directly into the internal buffer.
Returns bytes read, or 0 on EOF.
Sourcepub fn body_remaining(&self) -> usize
pub fn body_remaining(&self) -> usize
Bytes of data buffered beyond the parsed headers (body bytes).
Available after next() returns Some.
Sourcepub fn header(&self, name: &str) -> Option<&str>
pub fn header(&self, name: &str) -> Option<&str>
Look up a parsed response header by name (case-insensitive).
Returns None if headers haven’t been parsed yet or the header
is not found. Only valid after next() returns Some.
Sourcepub fn header_count(&self) -> usize
pub fn header_count(&self) -> usize
Number of parsed headers.
Sourcepub fn content_length(&self) -> Option<Result<usize, ()>>
pub fn content_length(&self) -> Option<Result<usize, ()>>
Cached Content-Length from parsed headers.
None = header absent, Some(Ok(n)) = valid, Some(Err(())) = present but malformed.
Sourcepub fn is_chunked(&self) -> bool
pub fn is_chunked(&self) -> bool
Whether Transfer-Encoding includes “chunked” (cached from parse).
Sourcepub fn set_body_consumed(&mut self, raw_bytes: usize)
pub fn set_body_consumed(&mut self, raw_bytes: usize)
Set the raw wire bytes consumed for the response body.
For Content-Length responses: equals Content-Length. For chunked responses: includes chunk framing overhead. For bodyless (1xx/204/304): 0.
Must be called before consume_response().
Sourcepub fn consume_response(&mut self)
pub fn consume_response(&mut self)
Advance past a consumed response, preserving any pipelined bytes.
Uses last_raw_body_bytes (set via set_body_consumed) to
determine how many wire bytes to skip. Call before parsing the
next response on a keep-alive connection.
Trait Implementations§
Source§impl ParserSink for ResponseReader
Lets a WireStream feed bytes directly into
the ResponseReader’s spare region — one fewer copy than going
through a slice intermediary.
impl ParserSink for ResponseReader
Lets a WireStream feed bytes directly into
the ResponseReader’s spare region — one fewer copy than going
through a slice intermediary.