Skip to content

Commit

Permalink
http2: turn Host header into authority during upgrade
Browse files Browse the repository at this point in the history
HTTP1 uses Host, but HTTP2 uses rather :authority cf HPACK
  • Loading branch information
catenacyber authored and victorjulien committed Sep 3, 2021
1 parent bb98a18 commit 75f75e1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rust/src/http2/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,13 @@ fn http2_tx_set_settings(state: &mut HTTP2State, input: &[u8]) {
}
}

fn http2_caseinsensitive_cmp(s1: &[u8], s2: &str) -> bool {
if let Ok(s) = std::str::from_utf8(s1) {
return s.to_lowercase() == s2;
}
return false;
}

#[no_mangle]
pub unsafe extern "C" fn rs_http2_tx_add_header(
state: &mut HTTP2State, name: *const u8, name_len: u32, value: *const u8, value_len: u32,
Expand All @@ -862,6 +869,8 @@ pub unsafe extern "C" fn rs_http2_tx_add_header(
let slice_value = build_slice!(value, value_len as usize);
if slice_name == "HTTP2-Settings".as_bytes() {
http2_tx_set_settings(state, slice_value)
} else if http2_caseinsensitive_cmp(slice_name, "host") {
http2_tx_set_header(state, ":authority".as_bytes(), slice_value)
} else {
http2_tx_set_header(state, slice_name, slice_value)
}
Expand Down

0 comments on commit 75f75e1

Please sign in to comment.