Skip to main content

ProxyParser

Struct ProxyParser 

Source
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

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProxyParser

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.