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:
parent
8759d79b03
commit
9b0fdca6e9
6 changed files with 24 additions and 35 deletions
|
@ -40,7 +40,7 @@ awc = { version = "3", default-features = false }
|
|||
base64 = "0.13"
|
||||
bytes = "1"
|
||||
futures-core = { version = "0.3.7", default-features = false }
|
||||
http = "0.2.5"
|
||||
http = "0.2.8"
|
||||
log = "0.4"
|
||||
socket2 = "0.4"
|
||||
serde = "1.0"
|
||||
|
|
|
@ -68,7 +68,7 @@ bytestring = "1"
|
|||
derive_more = "0.99.5"
|
||||
encoding_rs = "0.8"
|
||||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
http = "0.2.5"
|
||||
http = "0.2.8"
|
||||
httparse = "1.5.1"
|
||||
httpdate = "1.0.1"
|
||||
itoa = "1"
|
||||
|
|
|
@ -21,14 +21,14 @@ default = ["http"]
|
|||
|
||||
[dependencies]
|
||||
bytestring = ">=0.1.5, <2"
|
||||
http = { version = "0.2.3", optional = true }
|
||||
http = { version = "0.2.8", optional = true }
|
||||
regex = "1.5"
|
||||
serde = "1"
|
||||
tracing = { version = "0.1.30", default-features = false, features = ["log"] }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = { version = "0.3", features = ["html_reports"] }
|
||||
http = "0.2.5"
|
||||
http = "0.2.8"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
percent-encoding = "2.1"
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use std::{convert::Infallible, net::SocketAddr};
|
|||
|
||||
use actix_utils::future::{err, ok, Ready};
|
||||
use derive_more::{Display, Error};
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{
|
||||
dev::{AppConfig, Payload, RequestHead},
|
||||
|
@ -13,12 +12,9 @@ use crate::{
|
|||
FromRequest, HttpRequest, ResponseError,
|
||||
};
|
||||
|
||||
static X_FORWARDED_FOR: Lazy<HeaderName> =
|
||||
Lazy::new(|| HeaderName::from_static("x-forwarded-for"));
|
||||
static X_FORWARDED_HOST: Lazy<HeaderName> =
|
||||
Lazy::new(|| HeaderName::from_static("x-forwarded-host"));
|
||||
static X_FORWARDED_PROTO: Lazy<HeaderName> =
|
||||
Lazy::new(|| HeaderName::from_static("x-forwarded-proto"));
|
||||
static X_FORWARDED_FOR: HeaderName = HeaderName::from_static("x-forwarded-for");
|
||||
static X_FORWARDED_HOST: HeaderName = HeaderName::from_static("x-forwarded-host");
|
||||
static X_FORWARDED_PROTO: HeaderName = HeaderName::from_static("x-forwarded-proto");
|
||||
|
||||
/// Trim whitespace then any quote marks.
|
||||
fn unquote(val: &str) -> &str {
|
||||
|
@ -117,21 +113,21 @@ impl ConnectionInfo {
|
|||
}
|
||||
|
||||
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(|| Some("https").filter(|_| cfg.secure()))
|
||||
.unwrap_or("http")
|
||||
.to_owned();
|
||||
|
||||
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.uri.authority().map(Authority::as_str))
|
||||
.unwrap_or_else(|| cfg.host())
|
||||
.to_owned();
|
||||
|
||||
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);
|
||||
|
||||
let peer_addr = req.peer_addr.map(|addr| addr.ip().to_string());
|
||||
|
|
|
@ -220,32 +220,25 @@ static SUPPORTED_ENCODINGS_STRING: Lazy<String> = Lazy::new(|| {
|
|||
encoding.join(", ")
|
||||
});
|
||||
|
||||
static SUPPORTED_ENCODINGS: Lazy<Vec<Encoding>> = Lazy::new(|| {
|
||||
let mut encodings = vec![Encoding::identity()];
|
||||
|
||||
static SUPPORTED_ENCODINGS: &[Encoding] = &[
|
||||
Encoding::identity(),
|
||||
#[cfg(feature = "compress-brotli")]
|
||||
{
|
||||
encodings.push(Encoding::brotli());
|
||||
}
|
||||
|
||||
Encoding::brotli()
|
||||
},
|
||||
#[cfg(feature = "compress-gzip")]
|
||||
{
|
||||
encodings.push(Encoding::gzip());
|
||||
encodings.push(Encoding::deflate());
|
||||
}
|
||||
|
||||
Encoding::gzip()
|
||||
},
|
||||
#[cfg(feature = "compress-gzip")]
|
||||
{
|
||||
Encoding::deflate()
|
||||
},
|
||||
#[cfg(feature = "compress-zstd")]
|
||||
{
|
||||
encodings.push(Encoding::zstd());
|
||||
}
|
||||
|
||||
assert!(
|
||||
!encodings.is_empty(),
|
||||
"encodings can not be empty unless __compress feature has been explicitly enabled by itself"
|
||||
);
|
||||
|
||||
encodings
|
||||
});
|
||||
Encoding::zstd()
|
||||
},
|
||||
];
|
||||
|
||||
// move cfg(feature) to prevents_double_compressing if more tests are added
|
||||
#[cfg(feature = "compress-gzip")]
|
||||
|
|
|
@ -73,7 +73,7 @@ derive_more = "0.99.5"
|
|||
futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] }
|
||||
futures-util = { version = "0.3.7", default-features = false, features = ["alloc", "sink"] }
|
||||
h2 = "0.3.9"
|
||||
http = "0.2.5"
|
||||
http = "0.2.8"
|
||||
itoa = "1"
|
||||
log =" 0.4"
|
||||
mime = "0.3"
|
||||
|
|
Loading…
Reference in a new issue