parlov 0.8.0

HTTP oracle detection tool — systematic probing for RFC-compliant information leakage.
Documentation
//! Shared request-building utilities used across oracle pipeline modules.

use http::HeaderMap;
use parlov_core::Error;

/// Parses a slice of raw `"Name: Value"` header strings into a `HeaderMap`.
///
/// # Errors
///
/// Returns `Err` if any entry is not in `"Name: Value"` format, the header
/// name is invalid, or the header value is invalid.
pub(crate) fn parse_headers(raw: &[String]) -> Result<HeaderMap, Error> {
    let mut headers = HeaderMap::new();
    for entry in raw {
        let (name, value) = split_header(entry)?;
        let hname = name
            .parse::<http::header::HeaderName>()
            .map_err(|e| Error::Http(format!("invalid header name '{name}': {e}")))?;
        let hvalue = value
            .parse::<http::header::HeaderValue>()
            .map_err(|e| Error::Http(format!("invalid header value '{value}': {e}")))?;
        headers.insert(hname, hvalue);
    }
    Ok(headers)
}

/// Splits a single `"Name: Value"` header string into its name and value parts.
///
/// # Errors
///
/// Returns `Err` if the entry does not contain `": "`.
pub(crate) fn split_header(entry: &str) -> Result<(&str, &str), Error> {
    entry
        .split_once(": ")
        .ok_or_else(|| Error::Http(format!("header must be 'Name: Value', got '{entry}'")))
}