ProxyV1Parser

Struct ProxyV1Parser 

Source
pub struct ProxyV1Parser;
Expand description

A HaProxy protocol V1 parser.

It is assumed that the upstream has received the packet and splitted each header line. Input funtions expects that the input complies with the HaProxy protocl specs i.e

  • the message starts from identifier

  • separated with exactly one ASCII space

  • consists from ASCII printable chars only

  • ends with \r\n sequence and does not contain anything else.

Human-readable header format (Version 1)

This is the format specified in version 1 of the protocol. It consists in one line of US-ASCII text matching exactly the following block

So a 108-byte buffer is always enough to store all the line and a trailing zero for string processing. The receiver must wait for the CRLF sequence before starting to decode the addresses in order to ensure they are complete and properly parsed. If the CRLF sequence is not found in the first 107 characters, the receiver should declare the line invalid.

§Example

let pv1 = 
    ProxyV1Parser
        ::try_from_slice(b"PROXY TCP6 0acf:5d35:b4c4:731c:2442:2f17:c6f9:5b7f 4d7f:8980:38d6:e0c3:7301:70e9:f8ef:e393 23456 12345\r\n", false)
           .unwrap();

Implementations§

Source§

impl ProxyV1Parser

Source

pub fn try_from_str( value: &str, skip_strict_size_check: bool, ) -> HaProxRes<HapProtoV1>

Attempts to parse the value which was already converted to str.

It is assumed that a caller has verified that the value provided to function contains valid UTF8 char sequences and the message ends with \r\n and this string does not contain any other data after EOM.

§Arguments
  • value - a message to parse

  • skip_strict_size_check - if set to true, the max message length verification will be disabled.

§Returns

A HapProtoV1 is returned which contains parsed data.

The following error codes are returned:

Examples found in repository?
examples/example_v1.rs (lines 15-16)
4fn main()
5{
6    let res = 
7        ProxyHdrV1::from_str("192.168.1.1:333", "127.0.0.1:444")
8            .unwrap();
9
10    let out = res.to_string();
11
12    println!("{}", out);
13
14    let pv1 = 
15            ProxyV1Parser
16                ::try_from_str(out.as_str(), false)
17                    .unwrap();
18
19    assert_eq!(pv1.get_inet(), ProtocolV1Inet::Tcp4);
20    assert_eq!(pv1.get_src_addr(), Some("192.168.1.1".parse().unwrap()));
21    assert_eq!(pv1.get_src_port(), Some(333));
22    assert_eq!(pv1.get_dst_addr(), Some("127.0.0.1".parse().unwrap()));
23    assert_eq!(pv1.get_dst_port(), Some(444));
24}
Source

pub fn try_from_slice( value: &[u8], skip_strict_size_check: bool, ) -> HaProxRes<HapProtoV1>

Attempts to parse the value from a slice which contails a HaProxy related field.

It is assumed that a caller has split the header and provides a slice with the header only which ends with \r\n and this string does not contain any other data after EOM.

§Arguments
  • value - a message to parse

  • skip_strict_size_check - if set to true, the max message length verification will be disabled.

§Returns
§Returns

A HapProtoV1 is returned which contains parsed data.

The following error codes are returned:

Trait Implementations§

Source§

impl Debug for ProxyV1Parser

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.