mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
use const header values where possible
This commit is contained in:
@ -288,9 +288,11 @@ fn prepare_response(
|
||||
let _ = match size {
|
||||
BodySize::None | BodySize::Stream => None,
|
||||
|
||||
BodySize::Sized(0) => res
|
||||
.headers_mut()
|
||||
.insert(CONTENT_LENGTH, HeaderValue::from_static("0")),
|
||||
BodySize::Sized(0) => {
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
const HV_ZERO: HeaderValue = HeaderValue::from_static("0");
|
||||
res.headers_mut().insert(CONTENT_LENGTH, HV_ZERO)
|
||||
}
|
||||
|
||||
BodySize::Sized(len) => {
|
||||
let mut buf = itoa::Buffer::new();
|
||||
|
@ -45,13 +45,13 @@ pub enum ContentEncoding {
|
||||
impl ContentEncoding {
|
||||
/// Is the content compressed?
|
||||
#[inline]
|
||||
pub fn is_compression(self) -> bool {
|
||||
pub const fn is_compression(self) -> bool {
|
||||
matches!(self, ContentEncoding::Identity | ContentEncoding::Auto)
|
||||
}
|
||||
|
||||
/// Convert content encoding to string.
|
||||
#[inline]
|
||||
pub fn as_str(self) -> &'static str {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
ContentEncoding::Br => "br",
|
||||
ContentEncoding::Gzip => "gzip",
|
||||
|
@ -99,8 +99,9 @@ impl From<HandshakeError> for Response<BoxBody> {
|
||||
match err {
|
||||
HandshakeError::GetMethodRequired => {
|
||||
let mut res = Response::new(StatusCode::METHOD_NOT_ALLOWED);
|
||||
res.headers_mut()
|
||||
.insert(header::ALLOW, HeaderValue::from_static("GET"));
|
||||
#[allow(clippy::declare_interior_mutable_const)]
|
||||
const HV_GET: HeaderValue = HeaderValue::from_static("GET");
|
||||
res.headers_mut().insert(header::ALLOW, HV_GET);
|
||||
res
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user