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\nsequence 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
impl ProxyV1Parser
Sourcepub fn try_from_str(
value: &str,
skip_strict_size_check: bool,
) -> HaProxRes<HapProtoV1>
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 totrue, the max message length verification will be disabled.
§Returns
A HapProtoV1 is returned which contains parsed data.
The following error codes are returned:
-
crate::error::HaProxErrType::IncorrectBanner - incorrect header
-
crate::error::HaProxErrType::ProtocolMsgIncomplete -
valuedoes not end with\r\nseq.
Examples found in repository?
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}Sourcepub fn try_from_slice(
value: &[u8],
skip_strict_size_check: bool,
) -> HaProxRes<HapProtoV1>
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 totrue, the max message length verification will be disabled.
§Returns
§Returns
A HapProtoV1 is returned which contains parsed data.
The following error codes are returned:
-
crate::error::HaProxErrType::IncorrectBanner - incorrect header
-
crate::error::HaProxErrType::MalformedData - contains non UTF-8 seq or not ASCII or non printable ASCII.
-
crate::error::HaProxErrType::ProtocolMsgIncomplete -
valuedoes not end with\r\nseq.