pub struct Header {
pub name: SlicePos,
pub value: SlicePos,
}Expand description
A parsed header.
Fields§
§name: SlicePosHeader name, an ASCII token.
value: SlicePosHeader value, without surrounding whitespace, 0..0 if empty.
May contain HTAB, SP, visible ASCII and bytes 0x80..=0xFF, so it is
not guaranteed to be UTF-8.
Implementations§
Source§impl Header
impl Header
Sourcepub fn parse(&mut self, src: &[u8]) -> Result<HeaderParsed>
pub fn parse(&mut self, src: &[u8]) -> Result<HeaderParsed>
Parse a single header from a buffer of bytes.
If complete and successful, name and value positions are stored in
self and the returned HeaderParsed holds the position in the
buffer where parsing stopped.
Obsolete line folding is not supported: a line starting with SP or
HTAB is rejected with Error::HeaderName.
§Example
use ntex_httparse::{Status, Header, HeaderParsed};
let buf = b"Host: foo.bar \nAccept: */*\n\nblah blah";
let mut header = Header::default();
assert_eq!(header.parse(buf), Ok(Status::Complete(HeaderParsed::Header(15))));
assert_eq!(&buf[header.name.start..header.name.end], b"Host");
assert_eq!(&buf[header.value.start..header.value.end], b"foo.bar");Sourcepub fn parse_with_state(
&mut self,
src: &[u8],
st: &mut State,
) -> Result<HeaderParsed>
pub fn parse_with_state( &mut self, src: &[u8], st: &mut State, ) -> Result<HeaderParsed>
Parse a header, 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::HeaderName.
Trait Implementations§
impl Copy for Header
impl Eq for Header
impl StructuralPartialEq for Header
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
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