tests: share raw HTTP request/response helpers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-16 08:57:21 -04:00
1 parent 59956bb8b7
commit 66eb91bf01
3 files changed
+49 -45

No files matched your search

+7 -22
View File
@@ -1,4 +1,4 @@
//! Native TLS tests (WS-I T6): the real `slinuxm` binary serving HTTPS with
//! Native TLS tests: the real `slinuxm` binary serving HTTPS with
//! generated self-signed certificates.
use std::path::{Path, PathBuf};
@@ -13,6 +13,8 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio_rustls::TlsConnector;
mod common;
const BIN: &str = env!("CARGO_BIN_EXE_slinuxm");
struct Pair {
@@ -176,18 +178,7 @@ async fn https(
let der = &conn.peer_certificates().unwrap()[0];
hex(&Sha256::digest(der.as_ref()))
};
let mut req =
format!("{method} {path} HTTP/1.1\r\nHost: localhost:{port}\r\nConnection: close\r\n");
for (k, v) in headers {
req.push_str(&format!("{k}: {v}\r\n"));
}
if let Some(b) = body {
req.push_str(&format!("Content-Length: {}\r\n", b.len()));
}
req.push_str("\r\n");
if let Some(b) = body {
req.push_str(b);
}
let req = common::request(method, path, &format!("localhost:{port}"), headers, body);
tls.write_all(req.as_bytes()).await.unwrap();
let mut buf = Vec::new();
let mut chunk = [0u8; 4096];
@@ -198,17 +189,11 @@ async fn https(
Ok(Ok(n)) => buf.extend_from_slice(&chunk[..n]),
}
}
let text = String::from_utf8_lossy(&buf).into_owned();
let (head, body) = text.split_once("\r\n\r\n").unwrap_or((&text, ""));
let status = head
.split_whitespace()
.nth(1)
.and_then(|s| s.parse().ok())
.unwrap_or(0);
let (status, head, body) = common::parse_response(&buf);
Resp {
status,
head: head.to_lowercase(),
body: body.to_owned(),
head,
body,
peer_fp,
}
}