Files
telemt/src/web/http/response_test_support.rs
T
2026-09-06 18:51:13 +03:00

19 lines
728 B
Rust

/// Splits one complete raw HTTP response into head and body slices.
pub(in crate::web::http) fn split_response(response: &[u8]) -> (&[u8], &[u8]) {
let separator = response
.windows(4)
.position(|window| window == b"\r\n\r\n")
.unwrap();
(&response[..separator], &response[separator + 4..])
}
/// Returns one case-insensitive header value from a raw HTTP response head.
pub(in crate::web::http) fn response_header<'a>(headers: &'a [u8], name: &str) -> &'a str {
std::str::from_utf8(headers)
.unwrap()
.lines()
.filter_map(|line| line.split_once(':'))
.find_map(|(header, value)| header.eq_ignore_ascii_case(name).then_some(value.trim()))
.unwrap()
}