You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In actix-web-2.0.0, NormalizePath will convert the paths as following:
// => /
//v1// => /v1/
//v1//something => /v1/something
Current Behavior
When using TrailingSlash::Trim
// => /
//v1// => /v1
//v1//something => /v1/something
When using TrailingSlash::Always
// => /
//v1// => /v1/
//v1//something => /v1/something/
Possible Solution
Add an option called MergeOnly in TrailingSlash, which keeps the trailing slash's existance as it is.
This option should make NormalizePath compatible w/ actix-web-2.
Steps to Reproduce (for bugs)
#[actix_rt::test]asyncfnkeep_trailing_slash_unchange(){letmut app = init_service(App::new().wrap(NormalizePath(TrailingSlash::MergeOnly)).service(web::resource("/").to(HttpResponse::Ok)).service(web::resource("/v1/something").to(HttpResponse::Ok)).service(web::resource("/v1/").to(HttpResponse::Ok)),).await;let tests = vec![("/",true),// root paths should still work("/?query=test",true),("///",true),("/v1/something////",false),("/v1/something/",false),("//v1//something",true),("/v1/",true),("/v1",false),("/v1////",true),("//v1//",true),("///v1",false),];for(path, success)in tests {let req = TestRequest::with_uri(path).to_request();let res = call_service(&mut app, req).await;assert_eq!(res.status().is_success(), success);}}
Context
I wanna migrate from actix-web-2.0 to 3.0, but failed to access some of my resource.
Your Environment
Rust Version: rustc 1.46.0 (04488afe3 2020-08-24)
Actix Web Version: 3.0.2
The text was updated successfully, but these errors were encountered:
… with actix-web 2.0
Behavior of `NormalizePath` in actix-web 2.0 would keep the trailing slash's existance as it is,
which is different from that in 3.0.
This patch add a new option called `MergeOnly` in `TrailingSlash`, which only merge the trailing
slashes into one if there exist. This option makes `NormalizePath` able to be compatible with
actix-web 2.0 and makes it eaiser for users who want to migrate from 2.0 to 3.0.
This will closeactix#1694.
Expected Behavior
In actix-web-2.0.0,
NormalizePath
will convert the paths as following://
=>/
//v1//
=>/v1/
//v1//something
=>/v1/something
Current Behavior
When using
TrailingSlash::Trim
//
=>/
//v1//
=>/v1
//v1//something
=>/v1/something
When using
TrailingSlash::Always
//
=>/
//v1//
=>/v1/
//v1//something
=>/v1/something/
Possible Solution
Add an option called
MergeOnly
inTrailingSlash
, which keeps the trailing slash's existance as it is.This option should make
NormalizePath
compatible w/ actix-web-2.Steps to Reproduce (for bugs)
Context
I wanna migrate from actix-web-2.0 to 3.0, but failed to access some of my resource.
Your Environment
The text was updated successfully, but these errors were encountered: