mirror of https://github.com/rwf2/Rocket.git
Update 'state' to 0.6.
This commit is contained in:
parent
4b7d48967b
commit
b89a0039a7
|
@ -43,7 +43,7 @@ pin-project-lite = "0.2"
|
|||
memchr = "2"
|
||||
stable-pattern = "0.1"
|
||||
cookie = { version = "0.17.0", features = ["percent-encode"] }
|
||||
state = "0.5.3"
|
||||
state = "0.6"
|
||||
futures = { version = "0.3", default-features = false }
|
||||
|
||||
[dependencies.x509-parser]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Extension traits implemented by several HTTP types.
|
||||
|
||||
use smallvec::{Array, SmallVec};
|
||||
use state::Storage;
|
||||
use state::InitCell;
|
||||
|
||||
// TODO: It would be nice if we could somehow have one trait that could give us
|
||||
// either SmallVec or Vec.
|
||||
|
@ -106,10 +106,10 @@ impl<T: IntoOwned> IntoOwned for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: IntoOwned + Send + Sync> IntoOwned for Storage<T>
|
||||
impl<T: IntoOwned + Send + Sync> IntoOwned for InitCell<T>
|
||||
where T::Owned: Send + Sync
|
||||
{
|
||||
type Owned = Storage<T::Owned>;
|
||||
type Owned = InitCell<T::Owned>;
|
||||
|
||||
#[inline(always)]
|
||||
fn into_owned(self) -> Self::Owned {
|
||||
|
|
|
@ -51,7 +51,7 @@ use smallvec::SmallVec;
|
|||
/// [`exact_eq()`](MediaType::exact_eq()) method can be used.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MediaType {
|
||||
/// Storage for the entire media type string.
|
||||
/// InitCell for the entire media type string.
|
||||
pub(crate) source: Source,
|
||||
/// The top-level type.
|
||||
pub(crate) top: IndexedStr<'static>,
|
||||
|
|
|
@ -12,7 +12,7 @@ use tokio::time::Sleep;
|
|||
use tokio::io::{AsyncRead, AsyncWrite};
|
||||
use tokio::net::TcpStream;
|
||||
use hyper::server::accept::Accept;
|
||||
use state::Storage;
|
||||
use state::InitCell;
|
||||
|
||||
pub use tokio::net::TcpListener;
|
||||
|
||||
|
@ -29,7 +29,7 @@ pub struct CertificateData(pub Vec<u8>);
|
|||
|
||||
/// A collection of raw certificate data.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct Certificates(Arc<Storage<Vec<CertificateData>>>);
|
||||
pub struct Certificates(Arc<InitCell<Vec<CertificateData>>>);
|
||||
|
||||
impl From<Vec<CertificateData>> for Certificates {
|
||||
fn from(value: Vec<CertificateData>) -> Self {
|
||||
|
|
|
@ -40,7 +40,7 @@ pub struct TlsListener {
|
|||
///
|
||||
/// To work around this, we "lie" when `peer_certificates()` are requested and
|
||||
/// always return `Some(Certificates)`. Internally, `Certificates` is an
|
||||
/// `Arc<Storage<Vec<CertificateData>>>`, effectively a shared, thread-safe,
|
||||
/// `Arc<InitCell<Vec<CertificateData>>>`, effectively a shared, thread-safe,
|
||||
/// `OnceCell`. The cell is initially empty and is filled as soon as the
|
||||
/// handshake is complete. If the certificate data were to be requested prior to
|
||||
/// this point, it would be empty. However, in Rocket, we only request
|
||||
|
|
|
@ -440,12 +440,12 @@ impl<'a> Absolute<'a> {
|
|||
authority,
|
||||
path: Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(path)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
},
|
||||
query: match query {
|
||||
Some(query) => Some(Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(query)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
}),
|
||||
None => None,
|
||||
},
|
||||
|
|
|
@ -164,12 +164,12 @@ impl<'a> Origin<'a> {
|
|||
source: None,
|
||||
path: Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(path)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
},
|
||||
query: match query {
|
||||
Some(query) => Some(Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(query)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
}),
|
||||
None => None,
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::hash::Hash;
|
|||
use std::borrow::Cow;
|
||||
use std::fmt::Write;
|
||||
|
||||
use state::Storage;
|
||||
use state::InitCell;
|
||||
|
||||
use crate::{RawStr, ext::IntoOwned};
|
||||
use crate::uri::Segments;
|
||||
|
@ -14,12 +14,12 @@ use crate::parse::{IndexedStr, Extent};
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Data<'a, P: Part> {
|
||||
pub(crate) value: IndexedStr<'a>,
|
||||
pub(crate) decoded_segments: Storage<Vec<P::Raw>>,
|
||||
pub(crate) decoded_segments: InitCell<Vec<P::Raw>>,
|
||||
}
|
||||
|
||||
impl<'a, P: Part> Data<'a, P> {
|
||||
pub(crate) fn raw(value: Extent<&'a [u8]>) -> Self {
|
||||
Data { value: value.into(), decoded_segments: Storage::new() }
|
||||
Data { value: value.into(), decoded_segments: InitCell::new() }
|
||||
}
|
||||
|
||||
// INTERNAL METHOD.
|
||||
|
@ -27,7 +27,7 @@ impl<'a, P: Part> Data<'a, P> {
|
|||
pub fn new<S: Into<Cow<'a, str>>>(value: S) -> Self {
|
||||
Data {
|
||||
value: IndexedStr::from(value.into()),
|
||||
decoded_segments: Storage::new(),
|
||||
decoded_segments: InitCell::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ impl<'a> Path<'a> {
|
|||
|
||||
Data {
|
||||
value: IndexedStr::from(Cow::Owned(path)),
|
||||
decoded_segments: Storage::new(),
|
||||
decoded_segments: InitCell::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ impl<'a> Path<'a> {
|
|||
/// assert_eq!(path_segs, &["a b", "b/c", "d", "e"]);
|
||||
/// ```
|
||||
pub fn segments(&self) -> Segments<'a, fmt::Path> {
|
||||
let cached = self.data.decoded_segments.get_or_set(|| {
|
||||
let cached = self.data.decoded_segments.get_or_init(|| {
|
||||
let (indexed, path) = (&self.data.value, self.raw());
|
||||
self.raw_segments()
|
||||
.filter(|r| !r.is_empty())
|
||||
|
@ -235,7 +235,7 @@ impl<'a> Query<'a> {
|
|||
|
||||
Some(Data {
|
||||
value: IndexedStr::from(Cow::Owned(query)),
|
||||
decoded_segments: Storage::new(),
|
||||
decoded_segments: InitCell::new(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ impl<'a> Query<'a> {
|
|||
/// assert_eq!(query_segs, &[("a b/", "some one@gmail.com"), ("&=2", "")]);
|
||||
/// ```
|
||||
pub fn segments(&self) -> Segments<'a, fmt::Query> {
|
||||
let cached = self.data.decoded_segments.get_or_set(|| {
|
||||
let cached = self.data.decoded_segments.get_or_init(|| {
|
||||
let (indexed, query) = (&self.data.value, self.raw());
|
||||
self.raw_segments()
|
||||
.filter(|s| !s.is_empty())
|
||||
|
|
|
@ -129,12 +129,12 @@ impl<'a> Reference<'a> {
|
|||
authority,
|
||||
path: Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(path)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
},
|
||||
query: match query {
|
||||
Some(query) => Some(Data {
|
||||
value: IndexedStr::Concrete(Cow::Borrowed(query)),
|
||||
decoded_segments: state::Storage::new(),
|
||||
decoded_segments: state::InitCell::new(),
|
||||
}),
|
||||
None => None,
|
||||
},
|
||||
|
|
|
@ -59,7 +59,7 @@ async-trait = "0.1.43"
|
|||
async-stream = "0.3.2"
|
||||
multer = { version = "2", features = ["tokio-io"] }
|
||||
tokio-stream = { version = "0.1.6", features = ["signal", "time"] }
|
||||
state = "0.5.1"
|
||||
state = "0.6"
|
||||
|
||||
[dependencies.rocket_codegen]
|
||||
version = "=0.5.0-rc.3"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use state::Container;
|
||||
use state::TypeMap;
|
||||
use figment::Figment;
|
||||
|
||||
use crate::{Catcher, Config, Rocket, Route, Shutdown};
|
||||
|
@ -83,7 +83,7 @@ phases! {
|
|||
pub(crate) catchers: Vec<Catcher>,
|
||||
pub(crate) fairings: Fairings,
|
||||
pub(crate) figment: Figment,
|
||||
pub(crate) state: Container![Send + Sync],
|
||||
pub(crate) state: TypeMap![Send + Sync],
|
||||
}
|
||||
|
||||
/// The second launch [`Phase`]: post-build but pre-orbit. See
|
||||
|
@ -97,7 +97,7 @@ phases! {
|
|||
pub(crate) fairings: Fairings,
|
||||
pub(crate) figment: Figment,
|
||||
pub(crate) config: Config,
|
||||
pub(crate) state: Container![Send + Sync],
|
||||
pub(crate) state: TypeMap![Send + Sync],
|
||||
pub(crate) shutdown: Shutdown,
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ phases! {
|
|||
pub(crate) fairings: Fairings,
|
||||
pub(crate) figment: Figment,
|
||||
pub(crate) config: Config,
|
||||
pub(crate) state: Container![Send + Sync],
|
||||
pub(crate) state: TypeMap![Send + Sync],
|
||||
pub(crate) shutdown: Shutdown,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::{future::Future, borrow::Cow, sync::Arc};
|
|||
use std::net::{IpAddr, SocketAddr};
|
||||
|
||||
use yansi::Paint;
|
||||
use state::{Container, Storage};
|
||||
use state::{TypeMap, InitCell};
|
||||
use futures::future::BoxFuture;
|
||||
use atomic::{Atomic, Ordering};
|
||||
|
||||
|
@ -46,9 +46,9 @@ pub(crate) struct RequestState<'r> {
|
|||
pub rocket: &'r Rocket<Orbit>,
|
||||
pub route: Atomic<Option<&'r Route>>,
|
||||
pub cookies: CookieJar<'r>,
|
||||
pub accept: Storage<Option<Accept>>,
|
||||
pub content_type: Storage<Option<ContentType>>,
|
||||
pub cache: Arc<Container![Send + Sync]>,
|
||||
pub accept: InitCell<Option<Accept>>,
|
||||
pub content_type: InitCell<Option<ContentType>>,
|
||||
pub cache: Arc<TypeMap![Send + Sync]>,
|
||||
pub host: Option<Host<'r>>,
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ impl<'r> Request<'r> {
|
|||
rocket,
|
||||
route: Atomic::new(None),
|
||||
cookies: CookieJar::new(rocket.config()),
|
||||
accept: Storage::new(),
|
||||
content_type: Storage::new(),
|
||||
cache: Arc::new(<Container![Send + Sync]>::new()),
|
||||
accept: InitCell::new(),
|
||||
content_type: InitCell::new(),
|
||||
cache: Arc::new(<TypeMap![Send + Sync]>::new()),
|
||||
host: None,
|
||||
}
|
||||
}
|
||||
|
@ -547,7 +547,7 @@ impl<'r> Request<'r> {
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn content_type(&self) -> Option<&ContentType> {
|
||||
self.state.content_type.get_or_set(|| {
|
||||
self.state.content_type.get_or_init(|| {
|
||||
self.headers().get_one("Content-Type").and_then(|v| v.parse().ok())
|
||||
}).as_ref()
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ impl<'r> Request<'r> {
|
|||
/// ```
|
||||
#[inline]
|
||||
pub fn accept(&self) -> Option<&Accept> {
|
||||
self.state.accept.get_or_set(|| {
|
||||
self.state.accept.get_or_init(|| {
|
||||
self.headers().get_one("Accept").and_then(|v| v.parse().ok())
|
||||
}).as_ref()
|
||||
}
|
||||
|
@ -926,11 +926,11 @@ impl<'r> Request<'r> {
|
|||
fn bust_header_cache(&mut self, name: &UncasedStr, replace: bool) {
|
||||
if name == "Content-Type" {
|
||||
if self.content_type().is_none() || replace {
|
||||
self.state.content_type = Storage::new();
|
||||
self.state.content_type = InitCell::new();
|
||||
}
|
||||
} else if name == "Accept" {
|
||||
if self.accept().is_none() || replace {
|
||||
self.state.accept = Storage::new();
|
||||
self.state.accept = InitCell::new();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use state::Storage;
|
||||
use state::InitCell;
|
||||
use yansi::Paint;
|
||||
|
||||
use crate::{Rocket, Request, Response, Orbit, Config};
|
||||
|
@ -72,7 +72,7 @@ pub struct Shield {
|
|||
/// Whether to enforce HSTS even though the user didn't enable it.
|
||||
force_hsts: AtomicBool,
|
||||
/// Headers pre-rendered at liftoff from the configured policies.
|
||||
rendered: Storage<Vec<Header<'static>>>,
|
||||
rendered: InitCell<Vec<Header<'static>>>,
|
||||
}
|
||||
|
||||
impl Default for Shield {
|
||||
|
@ -111,7 +111,7 @@ impl Shield {
|
|||
Shield {
|
||||
policies: HashMap::new(),
|
||||
force_hsts: AtomicBool::new(false),
|
||||
rendered: Storage::new(),
|
||||
rendered: InitCell::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ impl Shield {
|
|||
/// let shield = Shield::new().enable(NoSniff::default());
|
||||
/// ```
|
||||
pub fn enable<P: Policy>(mut self, policy: P) -> Self {
|
||||
self.rendered = Storage::new();
|
||||
self.rendered = InitCell::new();
|
||||
self.policies.insert(P::NAME.into(), Box::new(policy));
|
||||
self
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ impl Shield {
|
|||
/// let shield = Shield::default().disable::<NoSniff>();
|
||||
/// ```
|
||||
pub fn disable<P: Policy>(mut self) -> Self {
|
||||
self.rendered = Storage::new();
|
||||
self.rendered = InitCell::new();
|
||||
self.policies.remove(UncasedStr::new(P::NAME));
|
||||
self
|
||||
}
|
||||
|
@ -174,7 +174,7 @@ impl Shield {
|
|||
}
|
||||
|
||||
fn headers(&self) -> &[Header<'static>] {
|
||||
self.rendered.get_or_set(|| {
|
||||
self.rendered.get_or_init(|| {
|
||||
let mut headers: Vec<_> = self.policies.values()
|
||||
.map(|p| p.header())
|
||||
.collect();
|
||||
|
|
Loading…
Reference in New Issue