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

Function take_sni

gateway/src/proxy.rs:50–73  ·  view source on GitHub ↗
(stream: &mut TcpStream)

Source from the content-addressed store, hash-verified

48mod tls_terminate;
49
50async fn take_sni(stream: &mut TcpStream) -> Result<(Option<String>, Vec<u8>)> {
51 let mut buffer = vec![0u8; 4096];
52 let mut data_len = 0;
53 loop {
54 // read data from stream
55 let n = stream
56 .read(&mut buffer[data_len..])
57 .await
58 .context("failed to read from incoming tcp stream")?;
59 if n == 0 {
60 break;
61 }
62 data_len += n;
63
64 if let Some(sni) = extract_sni(&buffer[..data_len]) {
65 let sni = String::from_utf8(sni.to_vec()).context("sni: invalid utf-8")?;
66 debug!("got sni: {sni}");
67 buffer.truncate(data_len);
68 return Ok((Some(sni), buffer));
69 }
70 }
71 buffer.truncate(data_len);
72 Ok((None, buffer))
73}
74
75#[derive(Debug)]
76struct DstInfo {

Callers 1

handle_connectionFunction · 0.85

Calls 3

extract_sniFunction · 0.85
to_vecMethod · 0.80
truncateMethod · 0.80

Tested by

no test coverage detected