pub struct Request {
pub method: SlicePos,
pub path: SlicePos,
pub path_ascii: bool,
pub query: Option<usize>,
pub version: u8,
}Expand description
A parsed request line.
Only the request line is parsed, use Header for the headers that
follow it.
§Example
use ntex_httparse::{Request, State, Status};
let mut req = Request::default();
let mut st = State::default();
// incomplete data, the parser remembers its progress in `st`
let buf = b"GET /index.html HT";
assert_eq!(req.parse_with_state(buf, &mut st), Ok(Status::Partial));
let buf = b"GET /index.html HTTP/1.1\r\nHost: example.com\r\n\r\n";
assert_eq!(req.parse_with_state(buf, &mut st), Ok(Status::Complete(26)));
assert_eq!(&buf[req.method.start..req.method.end], b"GET");
assert_eq!(&buf[req.path.start..req.path.end], b"/index.html");Fields§
§method: SlicePosRequest method, an ASCII token.
path: SlicePosRequest target. May contain bytes 0x80..=0xFF, so it is not
guaranteed to be UTF-8.
path_ascii: booltrue if the request target contains only ASCII bytes, so it is valid
UTF-8 and needs no further UTF-8 check.
query: Option<usize>Position of the first ? in the request target, an index into the
parsed buffer like path, None if the target has no query.
version: u8HTTP version, 0 for HTTP/1.0 and 1 for HTTP/1.1.
Implementations§
Source§impl Request
impl Request
Sourcepub fn parse(&mut self, src: &[u8]) -> Result<usize>
pub fn parse(&mut self, src: &[u8]) -> Result<usize>
Parse a request line.
Returns the position right after the line ending, where the headers start. Empty lines before the request line are skipped.
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 request 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::Token.
Bytes accepted by earlier calls are not scanned again, so feeding the line in pieces takes linear time.