Skip to content

Commit 9124ee4

Browse files
authored
refactor(http2): use const headers in strip_connection_headers (#3203)
1 parent e20bcd5 commit 9124ee4

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/proto/h2/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ cfg_server! {
2929
/// Default initial stream window size defined in HTTP2 spec.
3030
pub(crate) const SPEC_WINDOW_SIZE: u32 = 65_535;
3131

32+
// List of connection headers from:
33+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
34+
//
35+
// TE headers are allowed in HTTP/2 requests as long as the value is "trailers", so they're
36+
// tested separately.
37+
const CONNECTION_HEADERS: [HeaderName; 5] = [
38+
HeaderName::from_static("keep-alive"),
39+
HeaderName::from_static("proxy-connection"),
40+
TRAILER,
41+
TRANSFER_ENCODING,
42+
UPGRADE,
43+
];
44+
3245
fn strip_connection_headers(headers: &mut HeaderMap, is_request: bool) {
33-
// List of connection headers from:
34-
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection
35-
//
36-
// TE headers are allowed in HTTP/2 requests as long as the value is "trailers", so they're
37-
// tested separately.
38-
let connection_headers = [
39-
HeaderName::from_lowercase(b"keep-alive").unwrap(),
40-
HeaderName::from_lowercase(b"proxy-connection").unwrap(),
41-
TRAILER,
42-
TRANSFER_ENCODING,
43-
UPGRADE,
44-
];
45-
46-
for header in connection_headers.iter() {
46+
for header in &CONNECTION_HEADERS {
4747
if headers.remove(header).is_some() {
4848
warn!("Connection header illegal in HTTP/2: {}", header.as_str());
4949
}

0 commit comments

Comments
 (0)