mirror of https://github.com/fafhrd91/actix-web
commit
ba4ca433c7
|
@ -3,6 +3,13 @@
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
|
||||||
|
|
||||||
|
## 3.0.2 - 2020-09-15
|
||||||
|
### Fixed
|
||||||
|
* `NormalizePath` when used with `TrailingSlash::Trim` no longer trims the root path "/". [#1678]
|
||||||
|
|
||||||
|
[#1678]: https://github.com/actix/actix-web/pull/1678
|
||||||
|
|
||||||
|
|
||||||
## 3.0.1 - 2020-09-13
|
## 3.0.1 - 2020-09-13
|
||||||
### Changed
|
### Changed
|
||||||
* `middleware::normalize::TrailingSlash` enum is now accessible. [#1673]
|
* `middleware::normalize::TrailingSlash` enum is now accessible. [#1673]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "3.0.1"
|
version = "3.0.2"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix web is a powerful, pragmatic, and extremely fast web framework for Rust."
|
description = "Actix web is a powerful, pragmatic, and extremely fast web framework for Rust."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
|
@ -79,6 +79,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
pub struct NormalizePathNormalization<S> {
|
pub struct NormalizePathNormalization<S> {
|
||||||
service: S,
|
service: S,
|
||||||
merge_slash: Regex,
|
merge_slash: Regex,
|
||||||
|
@ -113,6 +114,10 @@ where
|
||||||
// normalize multiple /'s to one /
|
// normalize multiple /'s to one /
|
||||||
let path = self.merge_slash.replace_all(&path, "/");
|
let path = self.merge_slash.replace_all(&path, "/");
|
||||||
|
|
||||||
|
// Ensure root paths are still resolvable. If resulting path is blank after previous step
|
||||||
|
// it means the path was one or more slashes. Reduce to single slash.
|
||||||
|
let path = if path.is_empty() { "/" } else { path.as_ref() };
|
||||||
|
|
||||||
// Check whether the path has been changed
|
// Check whether the path has been changed
|
||||||
//
|
//
|
||||||
// This check was previously implemented as string length comparison
|
// This check was previously implemented as string length comparison
|
||||||
|
@ -158,10 +163,23 @@ mod tests {
|
||||||
let mut app = init_service(
|
let mut app = init_service(
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(NormalizePath::default())
|
.wrap(NormalizePath::default())
|
||||||
|
.service(web::resource("/").to(HttpResponse::Ok))
|
||||||
.service(web::resource("/v1/something/").to(HttpResponse::Ok)),
|
.service(web::resource("/v1/something/").to(HttpResponse::Ok)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/?query=test").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("///").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/v1//something////").to_request();
|
let req = TestRequest::with_uri("/v1//something////").to_request();
|
||||||
let res = call_service(&mut app, req).await;
|
let res = call_service(&mut app, req).await;
|
||||||
assert!(res.status().is_success());
|
assert!(res.status().is_success());
|
||||||
|
@ -184,10 +202,24 @@ mod tests {
|
||||||
let mut app = init_service(
|
let mut app = init_service(
|
||||||
App::new()
|
App::new()
|
||||||
.wrap(NormalizePath(TrailingSlash::Trim))
|
.wrap(NormalizePath(TrailingSlash::Trim))
|
||||||
|
.service(web::resource("/").to(HttpResponse::Ok))
|
||||||
.service(web::resource("/v1/something").to(HttpResponse::Ok)),
|
.service(web::resource("/v1/something").to(HttpResponse::Ok)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
// root paths should still work
|
||||||
|
let req = TestRequest::with_uri("/").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("/?query=test").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
|
let req = TestRequest::with_uri("///").to_request();
|
||||||
|
let res = call_service(&mut app, req).await;
|
||||||
|
assert!(res.status().is_success());
|
||||||
|
|
||||||
let req = TestRequest::with_uri("/v1/something////").to_request();
|
let req = TestRequest::with_uri("/v1/something////").to_request();
|
||||||
let res = call_service(&mut app, req).await;
|
let res = call_service(&mut app, req).await;
|
||||||
assert!(res.status().is_success());
|
assert!(res.status().is_success());
|
||||||
|
|
|
@ -2,11 +2,13 @@
|
||||||
|
|
||||||
## Unreleased - 2020-xx-xx
|
## Unreleased - 2020-xx-xx
|
||||||
|
|
||||||
|
* add ability to set address for `TestServer` [#1645]
|
||||||
|
|
||||||
|
[#1645]: https://github.com/actix/actix-web/pull/1645
|
||||||
|
|
||||||
## 2.0.0 - 2020-09-11
|
## 2.0.0 - 2020-09-11
|
||||||
* Update actix-codec and actix-utils dependencies.
|
* Update actix-codec and actix-utils dependencies.
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-alpha.1 - 2020-05-23
|
## 2.0.0-alpha.1 - 2020-05-23
|
||||||
* Update the `time` dependency to 0.2.7
|
* Update the `time` dependency to 0.2.7
|
||||||
* Update `actix-connect` dependency to 2.0.0-alpha.2
|
* Update `actix-connect` dependency to 2.0.0-alpha.2
|
||||||
|
|
|
@ -44,12 +44,20 @@ pub use actix_testing::*;
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
pub async fn test_server<F: ServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
||||||
|
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||||
|
test_server_with_addr(tcp, factory).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start [`test server`](./fn.test_server.html) on a concrete Address
|
||||||
|
pub async fn test_server_with_addr<F: ServiceFactory<TcpStream>>(
|
||||||
|
tcp: net::TcpListener,
|
||||||
|
factory: F,
|
||||||
|
) -> TestServer {
|
||||||
let (tx, rx) = mpsc::channel();
|
let (tx, rx) = mpsc::channel();
|
||||||
|
|
||||||
// run server in separate thread
|
// run server in separate thread
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let sys = System::new("actix-test-server");
|
let sys = System::new("actix-test-server");
|
||||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
|
||||||
let local_addr = tcp.local_addr().unwrap();
|
let local_addr = tcp.local_addr().unwrap();
|
||||||
|
|
||||||
Server::build()
|
Server::build()
|
||||||
|
|
Loading…
Reference in New Issue