Skip to content

Commit

Permalink
refactor(http2): use const headers in strip_connection_headers (#3203)
Browse files Browse the repository at this point in the history
  • Loading branch information
srijs authored May 1, 2023
1 parent e20bcd5 commit 9124ee4
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/proto/h2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@ cfg_server! {
/// Default initial stream window size defined in HTTP2 spec.
pub(crate) const SPEC_WINDOW_SIZE: u32 = 65_535;

// List of connection headers from:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
//
// TE headers are allowed in HTTP/2 requests as long as the value is "trailers", so they're
// tested separately.
const CONNECTION_HEADERS: [HeaderName; 5] = [
HeaderName::from_static("keep-alive"),
HeaderName::from_static("proxy-connection"),
TRAILER,
TRANSFER_ENCODING,
UPGRADE,
];

fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
// List of connection headers from:
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
//
// TE headers are allowed in HTTP/2 requests as long as the value is "trailers", so they're
// tested separately.
let connection_headers = [
HeaderName::from_lowercase(b"keep-alive").unwrap(),
HeaderName::from_lowercase(b"proxy-connection").unwrap(),
TRAILER,
TRANSFER_ENCODING,
UPGRADE,
];

for header in connection_headers.iter() {
for header in &CONNECTION_HEADERS {
if headers.remove(header).is_some() {
warn!("Connection header illegal in HTTP/2: {}", header.as_str());
}
Expand Down

0 comments on commit 9124ee4

Please sign in to comment.