Function
read_v1_header
(mut stream: I, buffer: &mut [u8; READ_BUFFER_LEN])
Source from the content-addressed store, hash-verified
| 158 | } |
| 159 | |
| 160 | async fn read_v1_header<I>(mut stream: I, buffer: &mut [u8; READ_BUFFER_LEN]) -> Result<()> |
| 161 | where |
| 162 | I: AsyncRead + Unpin, |
| 163 | { |
| 164 | let mut end_found = false; |
| 165 | for i in V1_PREFIX_LEN..V1_MAX_LENGTH { |
| 166 | buffer[i] = stream.read_u8().await?; |
| 167 | |
| 168 | if [buffer[i - 1], buffer[i]] == V1_TERMINATOR { |
| 169 | end_found = true; |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | if !end_found { |
| 174 | bail!("no valid proxy protocol header detected (v1 terminator not found)"); |
| 175 | } |
| 176 | |
| 177 | Ok(()) |
| 178 | } |
| 179 | |
| 180 | #[cfg(test)] |
| 181 | mod tests { |
Tested by
no test coverage detected