pub struct ProxyParser { /* private fields */ }Available on crate feature
proxy only.Expand description
A sans-IO PROXY header parser for one connection.
§Examples
use net_io::{ProxyParser, ProxyProgress, ProxyVersions};
let mut parser = ProxyParser::new(ProxyVersions::Both, 1024);
let bytes = b"PROXY TCP4 192.0.2.1 198.51.100.2 51000 443\r\nGET / HTTP/1.1\r\n";
match parser.feed(bytes)? {
ProxyProgress::Done { header, consumed } => {
assert_eq!(&bytes[consumed..], b"GET / HTTP/1.1\r\n");
assert_eq!(header.source.unwrap().to_string(), "192.0.2.1:51000");
}
ProxyProgress::NeedMore { .. } => unreachable!(),
}Implementations§
Source§impl ProxyParser
impl ProxyParser
Sourcepub fn new(versions: ProxyVersions, v2_body_max: u16) -> ProxyParser
pub fn new(versions: ProxyVersions, v2_body_max: u16) -> ProxyParser
A parser accepting versions, refusing a v2 header whose body (after the
16 fixed bytes) is longer than v2_body_max.
Sourcepub fn feed<'a>(
&mut self,
input: &'a [u8],
) -> Result<ProxyProgress<'a>, ProxyError>
pub fn feed<'a>( &mut self, input: &'a [u8], ) -> Result<ProxyProgress<'a>, ProxyError>
Parses from input, which holds every byte received so far.
§Errors
ProxyError: the bytes are not an allowed header, or are malformed.
Trait Implementations§
Source§impl Clone for ProxyParser
impl Clone for ProxyParser
Auto Trait Implementations§
impl Freeze for ProxyParser
impl RefUnwindSafe for ProxyParser
impl Send for ProxyParser
impl Sync for ProxyParser
impl Unpin for ProxyParser
impl UnsafeUnpin for ProxyParser
impl UnwindSafe for ProxyParser
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