use specter::transport::h2::{HpackDecoder, HpackEncoder};
#[test]
fn test_uppercase_headers_are_not_lowercased() {
let mut encoder = HpackEncoder::chrome();
let headers = vec![
("Authorization".to_string(), "Bearer token".to_string()),
("Content-Type".to_string(), "application/json".to_string()),
("x-custom-Header".to_string(), "value".to_string()),
];
let encoded = encoder.encode_request("GET", "https", "example.com", "/resource", &headers);
let mut decoder = HpackDecoder::new();
let decoded = decoder.decode(&encoded).expect("Failed to decode headers");
let mut found_auth_upper = false;
let mut found_auth_lower = false;
let mut found_content_type_upper = false;
let mut found_content_type_lower = false;
let mut found_custom_mixed = false;
let mut found_custom_lower = false;
for (name, _value) in decoded {
if name == "Authorization" {
found_auth_upper = true;
}
if name == "authorization" {
found_auth_lower = true;
}
if name == "Content-Type" {
found_content_type_upper = true;
}
if name == "content-type" {
found_content_type_lower = true;
}
if name == "x-custom-Header" {
found_custom_mixed = true;
}
if name == "x-custom-header" {
found_custom_lower = true;
}
}
assert!(
!found_auth_upper,
"Found 'Authorization' (uppercase) - should have been lowercased"
);
assert!(
!found_content_type_upper,
"Found 'Content-Type' (uppercase) - should have been lowercased"
);
assert!(
!found_custom_mixed,
"Found 'x-custom-Header' (mixed) - should have been lowercased"
);
assert!(found_auth_lower, "Missing 'authorization' header");
assert!(found_content_type_lower, "Missing 'content-type' header");
assert!(found_custom_lower, "Missing 'x-custom-header' header");
}