mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-30 18:34:36 +01:00
make HttpRequest::extensions() readonly
This commit is contained in:
parent
48e05a2d87
commit
d9a4fadaae
@ -6,6 +6,9 @@
|
||||
* `HttpServer::start_ssl()` and `HttpServer::start_tls()` deprecated.
|
||||
Use `HttpServer::bind_ssl()` and `HttpServer::bind_tls()` instead.
|
||||
|
||||
* `HttpRequest::extensions()` returns read only reference to the request's Extension
|
||||
`HttpRequest::extensions_mut()` returns mutable reference.
|
||||
|
||||
|
||||
## Migration from 0.4 to 0.5
|
||||
|
||||
|
@ -195,17 +195,10 @@ impl<S> HttpRequest<S> {
|
||||
|
||||
/// Request extensions
|
||||
#[inline]
|
||||
pub fn extensions(&mut self) -> &mut Extensions {
|
||||
pub fn extensions(&self) -> &Extensions {
|
||||
&mut self.as_mut().extensions
|
||||
}
|
||||
|
||||
/// Request extensions
|
||||
#[inline]
|
||||
#[doc(hidden)]
|
||||
pub fn extensions_ro(&self) -> &Extensions {
|
||||
&self.as_ref().extensions
|
||||
}
|
||||
|
||||
/// Mutable refernece to a the request's extensions
|
||||
#[inline]
|
||||
pub fn extensions_mut(&mut self) -> &mut Extensions {
|
||||
|
@ -100,7 +100,7 @@ pub trait RequestIdentity {
|
||||
|
||||
impl<S> RequestIdentity for HttpRequest<S> {
|
||||
fn identity(&self) -> Option<&str> {
|
||||
if let Some(id) = self.extensions_ro().get::<IdentityBox>() {
|
||||
if let Some(id) = self.extensions().get::<IdentityBox>() {
|
||||
return id.0.identity();
|
||||
}
|
||||
None
|
||||
@ -183,7 +183,7 @@ impl<S: 'static, T: IdentityPolicy<S>> Middleware<S> for IdentityService<T> {
|
||||
.from_request(&mut req)
|
||||
.then(move |res| match res {
|
||||
Ok(id) => {
|
||||
req.extensions().insert(IdentityBox(Box::new(id)));
|
||||
req.extensions_mut().insert(IdentityBox(Box::new(id)));
|
||||
FutOk(None)
|
||||
}
|
||||
Err(err) => FutErr(err),
|
||||
@ -194,7 +194,7 @@ impl<S: 'static, T: IdentityPolicy<S>> Middleware<S> for IdentityService<T> {
|
||||
fn response(
|
||||
&self, req: &mut HttpRequest<S>, resp: HttpResponse,
|
||||
) -> Result<Response> {
|
||||
if let Some(mut id) = req.extensions().remove::<IdentityBox>() {
|
||||
if let Some(mut id) = req.extensions_mut().remove::<IdentityBox>() {
|
||||
id.0.write(resp)
|
||||
} else {
|
||||
Ok(Response::Done(resp))
|
||||
|
@ -116,7 +116,7 @@ impl Logger {
|
||||
|
||||
impl<S> Middleware<S> for Logger {
|
||||
fn start(&self, req: &mut HttpRequest<S>) -> Result<Started> {
|
||||
req.extensions().insert(StartTime(time::now()));
|
||||
req.extensions_mut().insert(StartTime(time::now()));
|
||||
Ok(Started::Done)
|
||||
}
|
||||
|
||||
|
@ -106,7 +106,7 @@ pub trait RequestSession {
|
||||
|
||||
impl<S> RequestSession for HttpRequest<S> {
|
||||
fn session(&mut self) -> Session {
|
||||
if let Some(s_impl) = self.extensions().get_mut::<Arc<SessionImplBox>>() {
|
||||
if let Some(s_impl) = self.extensions_mut().get_mut::<Arc<SessionImplBox>>() {
|
||||
if let Some(s) = Arc::get_mut(s_impl) {
|
||||
return Session(s.0.as_mut());
|
||||
}
|
||||
@ -206,7 +206,7 @@ impl<S: 'static, T: SessionBackend<S>> Middleware<S> for SessionStorage<T, S> {
|
||||
.from_request(&mut req)
|
||||
.then(move |res| match res {
|
||||
Ok(sess) => {
|
||||
req.extensions()
|
||||
req.extensions_mut()
|
||||
.insert(Arc::new(SessionImplBox(Box::new(sess))));
|
||||
FutOk(None)
|
||||
}
|
||||
@ -218,7 +218,7 @@ impl<S: 'static, T: SessionBackend<S>> Middleware<S> for SessionStorage<T, S> {
|
||||
fn response(
|
||||
&self, req: &mut HttpRequest<S>, resp: HttpResponse,
|
||||
) -> Result<Response> {
|
||||
if let Some(s_box) = req.extensions().remove::<Arc<SessionImplBox>>() {
|
||||
if let Some(s_box) = req.extensions_mut().remove::<Arc<SessionImplBox>>() {
|
||||
s_box.0.write(resp)
|
||||
} else {
|
||||
Ok(Response::Done(resp))
|
||||
|
Loading…
Reference in New Issue
Block a user