mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-05 18:27:07 +01:00
Remove AddExtensionLayer
(#807)
* Remove `AddExtensionLayer` Its deprecated on 0.4.x so we can remove it from `main`. * changelog
This commit is contained in:
parent
768d8a8218
commit
2de202da40
5 changed files with 14 additions and 51 deletions
|
@ -56,6 +56,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- `MatchedPathRejection`
|
- `MatchedPathRejection`
|
||||||
- `WebSocketUpgradeRejection`
|
- `WebSocketUpgradeRejection`
|
||||||
- **breaking:** `Redirect::found` has been removed ([#800])
|
- **breaking:** `Redirect::found` has been removed ([#800])
|
||||||
|
- **breaking:** `AddExtensionLayer` has been removed. Use `Extension` instead. It now implements
|
||||||
|
`tower::Layer` ([#807])
|
||||||
- **fixed:** Set `Allow` header when responding with `405 Method Not Allowed` ([#733])
|
- **fixed:** Set `Allow` header when responding with `405 Method Not Allowed` ([#733])
|
||||||
- **fixed:** Correctly set the `Content-Length` header for response to `HEAD`
|
- **fixed:** Correctly set the `Content-Length` header for response to `HEAD`
|
||||||
requests ([#734])
|
requests ([#734])
|
||||||
|
@ -76,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#797]: https://github.com/tokio-rs/axum/pull/797
|
[#797]: https://github.com/tokio-rs/axum/pull/797
|
||||||
[#800]: https://github.com/tokio-rs/axum/pull/800
|
[#800]: https://github.com/tokio-rs/axum/pull/800
|
||||||
[#801]: https://github.com/tokio-rs/axum/pull/801
|
[#801]: https://github.com/tokio-rs/axum/pull/801
|
||||||
|
[#807]: https://github.com/tokio-rs/axum/pull/807
|
||||||
|
|
||||||
# 0.4.4 (13. January, 2022)
|
# 0.4.4 (13. January, 2022)
|
||||||
|
|
||||||
|
|
|
@ -2,41 +2,8 @@
|
||||||
|
|
||||||
use http::Request;
|
use http::Request;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tower_layer::Layer;
|
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
|
|
||||||
/// [`Layer`] for adding some shareable value to [request extensions].
|
|
||||||
///
|
|
||||||
/// See [Sharing state with handlers](index.html#sharing-state-with-handlers)
|
|
||||||
/// for more details.
|
|
||||||
///
|
|
||||||
/// [request extensions]: https://docs.rs/http/latest/http/struct.Extensions.html
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub struct AddExtensionLayer<T> {
|
|
||||||
value: T,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> AddExtensionLayer<T> {
|
|
||||||
/// Create a new [`AddExtensionLayer`].
|
|
||||||
pub fn new(value: T) -> Self {
|
|
||||||
Self { value }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<S, T> Layer<S> for AddExtensionLayer<T>
|
|
||||||
where
|
|
||||||
T: Clone,
|
|
||||||
{
|
|
||||||
type Service = AddExtension<S, T>;
|
|
||||||
|
|
||||||
fn layer(&self, inner: S) -> Self::Service {
|
|
||||||
AddExtension {
|
|
||||||
inner,
|
|
||||||
value: self.value.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Middleware for adding some shareable value to [request extensions].
|
/// Middleware for adding some shareable value to [request extensions].
|
||||||
///
|
///
|
||||||
/// See [Sharing state with handlers](index.html#sharing-state-with-handlers)
|
/// See [Sharing state with handlers](index.html#sharing-state-with-handlers)
|
||||||
|
@ -49,13 +16,6 @@ pub struct AddExtension<S, T> {
|
||||||
pub(crate) value: T,
|
pub(crate) value: T,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, T> AddExtension<S, T> {
|
|
||||||
/// Create a new [`AddExtensionLayer`].
|
|
||||||
pub fn layer(value: T) -> AddExtensionLayer<T> {
|
|
||||||
AddExtensionLayer::new(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<ResBody, S, T> Service<Request<ResBody>> for AddExtension<S, T>
|
impl<ResBody, S, T> Service<Request<ResBody>> for AddExtension<S, T>
|
||||||
where
|
where
|
||||||
S: Service<Request<ResBody>>,
|
S: Service<Request<ResBody>>,
|
||||||
|
|
|
@ -376,7 +376,7 @@ use axum::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, Response},
|
||||||
routing::get,
|
routing::get,
|
||||||
AddExtensionLayer, Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -416,7 +416,7 @@ async fn handler(user: AuthenticatedUser) {
|
||||||
|
|
||||||
let state = State { /* ... */ };
|
let state = State { /* ... */ };
|
||||||
|
|
||||||
let app = Router::new().route("/", get(handler)).layer(AddExtensionLayer::new(state));
|
let app = Router::new().route("/", get(handler)).layer(Extension(state));
|
||||||
# async {
|
# async {
|
||||||
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
||||||
# };
|
# };
|
||||||
|
|
|
@ -23,7 +23,7 @@ once, instead of calling `layer` (or `route_layer`) repeatedly:
|
||||||
```rust
|
```rust
|
||||||
use axum::{
|
use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
AddExtensionLayer,
|
Extension,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
use tower_http::{trace::TraceLayer};
|
use tower_http::{trace::TraceLayer};
|
||||||
|
@ -39,7 +39,7 @@ let app = Router::new()
|
||||||
.layer(
|
.layer(
|
||||||
ServiceBuilder::new()
|
ServiceBuilder::new()
|
||||||
.layer(TraceLayer::new_for_http())
|
.layer(TraceLayer::new_for_http())
|
||||||
.layer(AddExtensionLayer::new(State {}))
|
.layer(Extension(State {}))
|
||||||
);
|
);
|
||||||
# async {
|
# async {
|
||||||
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
||||||
|
@ -74,9 +74,9 @@ use axum::{routing::get, Router};
|
||||||
|
|
||||||
async fn handler() {}
|
async fn handler() {}
|
||||||
|
|
||||||
# let layer_one = axum::AddExtensionLayer::new(());
|
# let layer_one = axum::Extension(());
|
||||||
# let layer_two = axum::AddExtensionLayer::new(());
|
# let layer_two = axum::Extension(());
|
||||||
# let layer_three = axum::AddExtensionLayer::new(());
|
# let layer_three = axum::Extension(());
|
||||||
#
|
#
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(handler))
|
.route("/", get(handler))
|
||||||
|
@ -130,9 +130,9 @@ use axum::{routing::get, Router};
|
||||||
|
|
||||||
async fn handler() {}
|
async fn handler() {}
|
||||||
|
|
||||||
# let layer_one = axum::AddExtensionLayer::new(());
|
# let layer_one = axum::Extension(());
|
||||||
# let layer_two = axum::AddExtensionLayer::new(());
|
# let layer_two = axum::Extension(());
|
||||||
# let layer_three = axum::AddExtensionLayer::new(());
|
# let layer_three = axum::Extension(());
|
||||||
#
|
#
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
.route("/", get(handler))
|
.route("/", get(handler))
|
||||||
|
|
|
@ -409,7 +409,7 @@ pub mod routing;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test_helpers;
|
mod test_helpers;
|
||||||
|
|
||||||
pub use add_extension::{AddExtension, AddExtensionLayer};
|
pub use add_extension::AddExtension;
|
||||||
#[doc(no_inline)]
|
#[doc(no_inline)]
|
||||||
pub use async_trait::async_trait;
|
pub use async_trait::async_trait;
|
||||||
#[cfg(feature = "headers")]
|
#[cfg(feature = "headers")]
|
||||||
|
|
Loading…
Reference in a new issue