mirror of
https://github.com/actix/actix-web.git
synced 2025-02-02 12:22:20 +00:00
"deprecate" calls to NormalizePath::default
This commit is contained in:
parent
dade818eba
commit
c50eef6166
2 changed files with 23 additions and 4 deletions
|
@ -3,7 +3,8 @@
|
||||||
* The default `NormalizePath` behavior now strips trailing slashes by default. This was
|
* The default `NormalizePath` behavior now strips trailing slashes by default. This was
|
||||||
previously documented to be the case in v3 but the behavior now matches. The effect is that
|
previously documented to be the case in v3 but the behavior now matches. The effect is that
|
||||||
routes defined with trailing slashes will become inaccessible when
|
routes defined with trailing slashes will become inaccessible when
|
||||||
using `NormalizePath::default()`.
|
using `NormalizePath::default()`. As such, calling `NormalizePath::default()` will log a warning.
|
||||||
|
It is advised that the `new` method be used instead.
|
||||||
|
|
||||||
Before: `#[get("/test/")]`
|
Before: `#[get("/test/")]`
|
||||||
After: `#[get("/test")]`
|
After: `#[get("/test")]`
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl Default for TrailingSlash {
|
||||||
///
|
///
|
||||||
/// # actix_web::rt::System::new().block_on(async {
|
/// # actix_web::rt::System::new().block_on(async {
|
||||||
/// let app = App::new()
|
/// let app = App::new()
|
||||||
/// .wrap(middleware::NormalizePath::default())
|
/// .wrap(middleware::NormalizePath::trim())
|
||||||
/// .route("/test", web::get().to(|| async { "test" }))
|
/// .route("/test", web::get().to(|| async { "test" }))
|
||||||
/// .route("/unmatchable/", web::get().to(|| async { "unmatchable" }));
|
/// .route("/unmatchable/", web::get().to(|| async { "unmatchable" }));
|
||||||
///
|
///
|
||||||
|
@ -85,13 +85,31 @@ impl Default for TrailingSlash {
|
||||||
/// assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
/// assert_eq!(res.status(), StatusCode::NOT_FOUND);
|
||||||
/// # })
|
/// # })
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct NormalizePath(TrailingSlash);
|
pub struct NormalizePath(TrailingSlash);
|
||||||
|
|
||||||
|
impl Default for NormalizePath {
|
||||||
|
fn default() -> Self {
|
||||||
|
log::warn!(
|
||||||
|
"`NormalizePath::default()` is deprecated. The default trailing slash behavior changed \
|
||||||
|
in v4 from `Always` to `Trim`. Update your call to `NormalizePath::new(...)`."
|
||||||
|
);
|
||||||
|
|
||||||
|
Self(TrailingSlash::Trim)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl NormalizePath {
|
impl NormalizePath {
|
||||||
/// Create new `NormalizePath` middleware with the specified trailing slash style.
|
/// Create new `NormalizePath` middleware with the specified trailing slash style.
|
||||||
pub fn new(trailing_slash_style: TrailingSlash) -> Self {
|
pub fn new(trailing_slash_style: TrailingSlash) -> Self {
|
||||||
NormalizePath(trailing_slash_style)
|
Self(trailing_slash_style)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Constructs a new `NormalizePath` middleware with [trim](TrailingSlash::Trim) semantics.
|
||||||
|
///
|
||||||
|
/// Use this instead of `NormalizePath::default()` to avoid deprecation warning.
|
||||||
|
pub fn trim() -> Self {
|
||||||
|
Self::new(TrailingSlash::Trim)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue