pub struct Request {
pub method: SlicePos,
pub path: SlicePos,
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.
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.
Trait Implementations§
impl Copy for Request
impl Eq for Request
impl StructuralPartialEq for Request
Auto Trait Implementations§
impl Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more