1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-28 20:41:48 +00:00

Remove some unnecessary uses of once_cell::sync::Lazy (#2816)

This commit is contained in:
Expyron 2022-07-22 21:18:38 +02:00 committed by GitHub
parent 8759d79b03
commit 9b0fdca6e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 35 deletions

View file

@ -40,7 +40,7 @@ awc = { version = "3", default-features = false }
base64 = "0.13" base64 = "0.13"
bytes = "1" bytes = "1"
futures-core = { version = "0.3.7", default-features = false } futures-core = { version = "0.3.7", default-features = false }
http = "0.2.5" http = "0.2.8"
log = "0.4" log = "0.4"
socket2 = "0.4" socket2 = "0.4"
serde = "1.0" serde = "1.0"

View file

@ -68,7 +68,7 @@ bytestring = "1"
derive_more = "0.99.5" derive_more = "0.99.5"
encoding_rs = "0.8" encoding_rs = "0.8"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
http = "0.2.5" http = "0.2.8"
httparse = "1.5.1" httparse = "1.5.1"
httpdate = "1.0.1" httpdate = "1.0.1"
itoa = "1" itoa = "1"

View file

@ -21,14 +21,14 @@ default = ["http"]
[dependencies] [dependencies]
bytestring = ">=0.1.5, <2" bytestring = ">=0.1.5, <2"
http = { version = "0.2.3", optional = true } http = { version = "0.2.8", optional = true }
regex = "1.5" regex = "1.5"
serde = "1" serde = "1"
tracing = { version = "0.1.30", default-features = false, features = ["log"] } tracing = { version = "0.1.30", default-features = false, features = ["log"] }
[dev-dependencies] [dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] } criterion = { version = "0.3", features = ["html_reports"] }
http = "0.2.5" http = "0.2.8"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
percent-encoding = "2.1" percent-encoding = "2.1"

View file

@ -2,7 +2,6 @@ use std::{convert::Infallible, net::SocketAddr};
use actix_utils::future::{err, ok, Ready}; use actix_utils::future::{err, ok, Ready};
use derive_more::{Display, Error}; use derive_more::{Display, Error};
use once_cell::sync::Lazy;
use crate::{ use crate::{
dev::{AppConfig, Payload, RequestHead}, dev::{AppConfig, Payload, RequestHead},
@ -13,12 +12,9 @@ use crate::{
FromRequest, HttpRequest, ResponseError, FromRequest, HttpRequest, ResponseError,
}; };
static X_FORWARDED_FOR: Lazy<HeaderName> = static X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
Lazy::new(|| HeaderName::from_static("x-forwarded-for")); static X_FORWARDED_HOST: HeaderName = HeaderName::from_static("x-forwarded-host");
static X_FORWARDED_HOST: Lazy<HeaderName> = static X_FORWARDED_PROTO: HeaderName = HeaderName::from_static("x-forwarded-proto");
Lazy::new(|| HeaderName::from_static("x-forwarded-host"));
static X_FORWARDED_PROTO: Lazy<HeaderName> =
Lazy::new(|| HeaderName::from_static("x-forwarded-proto"));
/// Trim whitespace then any quote marks. /// Trim whitespace then any quote marks.
fn unquote(val: &str) -> &str { fn unquote(val: &str) -> &str {
@ -117,21 +113,21 @@ impl ConnectionInfo {
} }
let scheme = scheme let scheme = scheme
.or_else(|| first_header_value(req, &*X_FORWARDED_PROTO)) .or_else(|| first_header_value(req, &X_FORWARDED_PROTO))
.or_else(|| req.uri.scheme().map(Scheme::as_str)) .or_else(|| req.uri.scheme().map(Scheme::as_str))
.or_else(|| Some("https").filter(|_| cfg.secure())) .or_else(|| Some("https").filter(|_| cfg.secure()))
.unwrap_or("http") .unwrap_or("http")
.to_owned(); .to_owned();
let host = host let host = host
.or_else(|| first_header_value(req, &*X_FORWARDED_HOST)) .or_else(|| first_header_value(req, &X_FORWARDED_HOST))
.or_else(|| req.headers.get(&header::HOST)?.to_str().ok()) .or_else(|| req.headers.get(&header::HOST)?.to_str().ok())
.or_else(|| req.uri.authority().map(Authority::as_str)) .or_else(|| req.uri.authority().map(Authority::as_str))
.unwrap_or_else(|| cfg.host()) .unwrap_or_else(|| cfg.host())
.to_owned(); .to_owned();
let realip_remote_addr = realip_remote_addr let realip_remote_addr = realip_remote_addr
.or_else(|| first_header_value(req, &*X_FORWARDED_FOR)) .or_else(|| first_header_value(req, &X_FORWARDED_FOR))
.map(str::to_owned); .map(str::to_owned);
let peer_addr = req.peer_addr.map(|addr| addr.ip().to_string()); let peer_addr = req.peer_addr.map(|addr| addr.ip().to_string());

View file

@ -220,32 +220,25 @@ static SUPPORTED_ENCODINGS_STRING: Lazy<String> = Lazy::new(|| {
encoding.join(", ") encoding.join(", ")
}); });
static SUPPORTED_ENCODINGS: Lazy<Vec<Encoding>> = Lazy::new(|| { static SUPPORTED_ENCODINGS: &[Encoding] = &[
let mut encodings = vec![Encoding::identity()]; Encoding::identity(),
#[cfg(feature = "compress-brotli")] #[cfg(feature = "compress-brotli")]
{ {
encodings.push(Encoding::brotli()); Encoding::brotli()
} },
#[cfg(feature = "compress-gzip")] #[cfg(feature = "compress-gzip")]
{ {
encodings.push(Encoding::gzip()); Encoding::gzip()
encodings.push(Encoding::deflate()); },
} #[cfg(feature = "compress-gzip")]
{
Encoding::deflate()
},
#[cfg(feature = "compress-zstd")] #[cfg(feature = "compress-zstd")]
{ {
encodings.push(Encoding::zstd()); Encoding::zstd()
} },
];
assert!(
!encodings.is_empty(),
"encodings can not be empty unless __compress feature has been explicitly enabled by itself"
);
encodings
});
// move cfg(feature) to prevents_double_compressing if more tests are added // move cfg(feature) to prevents_double_compressing if more tests are added
#[cfg(feature = "compress-gzip")] #[cfg(feature = "compress-gzip")]

View file

@ -73,7 +73,7 @@ derive_more = "0.99.5"
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] } futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
h2 = "0.3.9" h2 = "0.3.9"
http = "0.2.5" http = "0.2.8"
itoa = "1" itoa = "1"
log =" 0.4" log =" 0.4"
mime = "0.3" mime = "0.3"