diff --git a/MIGRATION.md b/MIGRATION.md index 4e8cad369..45c35d7de 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -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 diff --git a/src/httprequest.rs b/src/httprequest.rs index 5b3c6619d..ab2c99fef 100644 --- a/src/httprequest.rs +++ b/src/httprequest.rs @@ -195,17 +195,10 @@ impl HttpRequest { /// 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 { diff --git a/src/middleware/identity.rs b/src/middleware/identity.rs index 50df4df4a..ce18e858a 100644 --- a/src/middleware/identity.rs +++ b/src/middleware/identity.rs @@ -100,7 +100,7 @@ pub trait RequestIdentity { impl RequestIdentity for HttpRequest { fn identity(&self) -> Option<&str> { - if let Some(id) = self.extensions_ro().get::() { + if let Some(id) = self.extensions().get::() { return id.0.identity(); } None @@ -183,7 +183,7 @@ impl> Middleware for IdentityService { .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> Middleware for IdentityService { fn response( &self, req: &mut HttpRequest, resp: HttpResponse, ) -> Result { - if let Some(mut id) = req.extensions().remove::() { + if let Some(mut id) = req.extensions_mut().remove::() { id.0.write(resp) } else { Ok(Response::Done(resp)) diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index 289647189..adfc3d2b0 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -116,7 +116,7 @@ impl Logger { impl Middleware for Logger { fn start(&self, req: &mut HttpRequest) -> Result { - req.extensions().insert(StartTime(time::now())); + req.extensions_mut().insert(StartTime(time::now())); Ok(Started::Done) } diff --git a/src/middleware/session.rs b/src/middleware/session.rs index 4e2f9976d..c0c366319 100644 --- a/src/middleware/session.rs +++ b/src/middleware/session.rs @@ -106,7 +106,7 @@ pub trait RequestSession { impl RequestSession for HttpRequest { fn session(&mut self) -> Session { - if let Some(s_impl) = self.extensions().get_mut::>() { + if let Some(s_impl) = self.extensions_mut().get_mut::>() { if let Some(s) = Arc::get_mut(s_impl) { return Session(s.0.as_mut()); } @@ -206,7 +206,7 @@ impl> Middleware for SessionStorage { .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> Middleware for SessionStorage { fn response( &self, req: &mut HttpRequest, resp: HttpResponse, ) -> Result { - if let Some(s_box) = req.extensions().remove::>() { + if let Some(s_box) = req.extensions_mut().remove::>() { s_box.0.write(resp) } else { Ok(Response::Done(resp))