MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / read_proxy_header

Function read_proxy_header

gateway/src/pp.rs:98–125  ·  view source on GitHub ↗
(mut stream: I)

Source from the content-addressed store, hash-verified

96}
97
98async fn read_proxy_header<I>(mut stream: I) -> Result<(I, ProxyHeader)>
99where
100 I: AsyncRead + Unpin,
101{
102 let mut buffer = [0; READ_BUFFER_LEN];
103 let mut dynamic_buffer = None;
104
105 stream.read_exact(&mut buffer[..V1_PREFIX_LEN]).await?;
106
107 if &buffer[..V1_PREFIX_LEN] == V1_PROTOCOL_PREFIX.as_bytes() {
108 read_v1_header(&mut stream, &mut buffer).await?;
109 } else {
110 stream
111 .read_exact(&mut buffer[V1_PREFIX_LEN..V2_MINIMUM_LEN])
112 .await?;
113 if &buffer[..V2_PREFIX_LEN] == V2_PROTOCOL_PREFIX {
114 dynamic_buffer = read_v2_header(&mut stream, &mut buffer).await?;
115 } else {
116 bail!("no valid proxy protocol header detected");
117 }
118 }
119
120 let mut buffer = dynamic_buffer.as_deref().unwrap_or(&buffer[..]);
121
122 let header =
123 proxy_protocol::parse(&mut buffer).context("failed to parse proxy protocol header")?;
124 Ok((stream, header))
125}
126
127async fn read_v2_header<I>(
128 mut stream: I,

Callers 6

get_inbound_pp_headerFunction · 0.85
parses_v1_ipv4Function · 0.85
parses_v2_ipv4Function · 0.85
rejects_no_prefixFunction · 0.85

Calls 2

read_v1_headerFunction · 0.85
read_v2_headerFunction · 0.85

Tested by

no test coverage detected