From a3e19465acc662127a854842d4b4bfb642b8771d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 27 Dec 2021 18:25:47 +0100 Subject: [PATCH] Move header name validity checks to compile time (#661) --- axum/src/extract/ws.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 91250285..880ab1e2 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -215,13 +215,15 @@ impl WebSocketUpgrade { callback(socket).await; }); + #[allow(clippy::declare_interior_mutable_const)] + const UPGRADE: HeaderValue = HeaderValue::from_static("upgrade"); + #[allow(clippy::declare_interior_mutable_const)] + const WEBSOCKET: HeaderValue = HeaderValue::from_static("websocket"); + let mut builder = Response::builder() .status(StatusCode::SWITCHING_PROTOCOLS) - .header( - header::CONNECTION, - HeaderValue::from_str("upgrade").unwrap(), - ) - .header(header::UPGRADE, HeaderValue::from_str("websocket").unwrap()) + .header(header::CONNECTION, UPGRADE) + .header(header::UPGRADE, WEBSOCKET) .header( header::SEC_WEBSOCKET_ACCEPT, sign(self.sec_websocket_key.as_bytes()),