pub struct Response {
pub version: u8,
pub code: u16,
pub reason: SlicePos,
}Expand description
A parsed status line.
Only the status line is parsed, use Header for the headers that
follow it.
§Example
use ntex_httparse::{Response, Status};
let buf = b"HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n";
let mut res = Response::default();
assert_eq!(res.parse(buf), Ok(Status::Complete(24)));
assert_eq!(res.code, 404);
assert_eq!(&buf[res.reason.start..res.reason.end], b"Not Found");Fields§
§version: u8HTTP version, 0 for HTTP/1.0 and 1 for HTTP/1.1.
code: u16Status code, three digits.
reason: SlicePosReason phrase, empty if missing. A non-empty reason is ASCII, a reason
containing obs-text (bytes 0x80..=0xFF) is returned as empty.
Implementations§
Source§impl Response
impl Response
Sourcepub fn parse(&mut self, src: &[u8]) -> Result<usize>
pub fn parse(&mut self, src: &[u8]) -> Result<usize>
Parse a status line.
Returns the position right after the line ending, where the headers start. Empty lines before the status line are skipped. The reason phrase is optional.
Sourcepub fn parse_with_state(&mut self, src: &[u8], st: &mut State) -> Result<usize>
pub fn parse_with_state(&mut self, src: &[u8], st: &mut State) -> Result<usize>
Parse a status line, resuming from st saved by a previous Partial
result.
st must come from a previous call with the same buffer (which may have
grown since), or be State::default(). An invalid state returns
Error::Status.
Bytes accepted by earlier calls are not scanned again, so feeding the line in pieces takes linear time.