//! Helpers for parsing the `X-Strip-Nulls` header that controls null trimming.
use actix_web::HttpRequest;

/// Returns the raw header value for `X-Strip-Nulls` when present.
pub fn get_x_strip_nulls(req: &HttpRequest) -> Option<String> {
    req.headers()
        .get("X-Strip-Nulls")
        .and_then(|h| h.to_str().ok())
        .map(|s| s.to_string())
}

#[cfg(test)]
mod tests {
    use super::*;
    use actix_web::test::TestRequest;

    #[actix_web::test]
    async fn returns_none_when_missing() {
        let req: HttpRequest = TestRequest::default().to_http_request();
        assert!(get_x_strip_nulls(&req).is_none());
    }

    #[actix_web::test]
    async fn returns_value_when_present() {
        let req: HttpRequest = TestRequest::default()
            .insert_header(("X-Strip-Nulls", "true"))
            .to_http_request();
        assert_eq!(get_x_strip_nulls(&req).unwrap(), "true");
    }
}
