Merge branch 'master' into cookie-crate

This commit is contained in:
Rob Ede 2020-06-18 17:59:53 +01:00 committed by GitHub
commit 5f067b3c68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 12 deletions

View File

@ -2,11 +2,19 @@
## [Unreleased] ## [Unreleased]
### Added
* Re-export `actix_rt::main` as `actix_web::main`.
### Changed ### Changed
* Fix actix_http::h1::dispatcher so it returns when HW_BUFFER_SIZE is reached. Should reduce peak memory consumption during large uploads. [#1550] * Fix actix_http::h1::dispatcher so it returns when HW_BUFFER_SIZE is reached. Should reduce peak memory consumption during large uploads. [#1550]
* Migrate cookie handling to `cookie` crate. Actix-web no longer requires `ring` dependency. * Migrate cookie handling to `cookie` crate. Actix-web no longer requires `ring` dependency.
### Fixed
* `NormalizePath` improved consistency when path needs slashes added _and_ removed.
## [3.0.0-alpha.3] - 2020-05-21 ## [3.0.0-alpha.3] - 2020-05-21
### Added ### Added

View File

@ -69,7 +69,7 @@ actix-codec = "0.2.0"
actix-service = "1.0.2" actix-service = "1.0.2"
actix-utils = "1.0.6" actix-utils = "1.0.6"
actix-router = "0.2.4" actix-router = "0.2.4"
actix-rt = "1.0.0" actix-rt = "1.1.1"
actix-server = "1.0.0" actix-server = "1.0.0"
actix-testing = "1.0.0" actix-testing = "1.0.0"
actix-macros = "0.1.0" actix-macros = "0.1.0"

View File

@ -53,7 +53,6 @@ Dependencies:
```toml ```toml
[dependencies] [dependencies]
actix-web = "2" actix-web = "2"
actix-rt = "1"
``` ```
Code: Code:
@ -66,7 +65,7 @@ async fn index(info: web::Path<(u32, String)>) -> impl Responder {
format!("Hello {}! id:{}", info.1, info.0) format!("Hello {}! id:{}", info.1, info.0)
} }
#[actix_rt::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().service(index)) HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")? .bind("127.0.0.1:8080")?

View File

@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
actix = "0.10.0-alpha.2" actix = "0.10.0-alpha.2"
actix-web = "3.0.0-alpha.3" actix-web = { version = "3.0.0-alpha.3", default-features = false }
actix-http = "2.0.0-alpha.4" actix-http = "2.0.0-alpha.4"
actix-codec = "0.2.0" actix-codec = "0.2.0"
bytes = "0.5.2" bytes = "0.5.2"

View File

@ -16,7 +16,7 @@ async fn no_params() -> &'static str {
"Hello world!\r\n" "Hello world!\r\n"
} }
#[actix_rt::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init(); env_logger::init();

View File

@ -1,6 +1,6 @@
use actix_http::Error; use actix_http::Error;
#[actix_rt::main] #[actix_web::main]
async fn main() -> Result<(), Error> { async fn main() -> Result<(), Error> {
std::env::set_var("RUST_LOG", "actix_http=trace"); std::env::set_var("RUST_LOG", "actix_http=trace");
env_logger::init(); env_logger::init();

View File

@ -20,7 +20,7 @@ async fn no_params() -> &'static str {
} }
#[cfg(unix)] #[cfg(unix)]
#[actix_rt::main] #[actix_web::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info"); std::env::set_var("RUST_LOG", "actix_server=info,actix_web=info");
env_logger::init(); env_logger::init();

View File

@ -112,6 +112,7 @@ pub use actix_web_codegen::*;
// re-export for convenience // re-export for convenience
pub use actix_http::Response as HttpResponse; pub use actix_http::Response as HttpResponse;
pub use actix_http::{body, cookie, http, Error, HttpMessage, ResponseError, Result}; pub use actix_http::{body, cookie, http, Error, HttpMessage, ResponseError, Result};
pub use actix_macros::{main, test as test_rt};
pub use crate::app::App; pub use crate::app::App;
pub use crate::extract::FromRequest; pub use crate::extract::FromRequest;

View File

@ -16,6 +16,7 @@ use crate::Error;
/// Performs following: /// Performs following:
/// ///
/// - Merges multiple slashes into one. /// - Merges multiple slashes into one.
/// - Appends a trailing slash if one is not present.
/// ///
/// ```rust /// ```rust
/// use actix_web::{web, http, middleware, App, HttpResponse}; /// use actix_web::{web, http, middleware, App, HttpResponse};
@ -75,14 +76,26 @@ where
fn call(&mut self, mut req: ServiceRequest) -> Self::Future { fn call(&mut self, mut req: ServiceRequest) -> Self::Future {
let head = req.head_mut(); let head = req.head_mut();
let original_path = head.uri.path();
// always add trailing slash, might be an extra one // always add trailing slash, might be an extra one
let path = head.uri.path().to_string() + "/"; let path = original_path.to_string() + "/";
let original_len = path.len();
// 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, "/");
if original_len != path.len() { // Check whether the path has been changed
//
// This check was previously implemented as string length comparison
//
// That approach fails when a trailing slash is added,
// and a duplicate slash is removed,
// since the length of the strings remains the same
//
// For example, the path "/v1//s" will be normalized to "/v1/s/"
// Both of the paths have the same length,
// so the change can not be deduced from the length comparison
if path != original_path {
let mut parts = head.uri.clone().into_parts(); let mut parts = head.uri.clone().into_parts();
let pq = parts.path_and_query.as_ref().unwrap(); let pq = parts.path_and_query.as_ref().unwrap();
@ -131,6 +144,10 @@ mod tests {
let req3 = TestRequest::with_uri("//v1//////something").to_request(); let req3 = TestRequest::with_uri("//v1//////something").to_request();
let res3 = call_service(&mut app, req3).await; let res3 = call_service(&mut app, req3).await;
assert!(res3.status().is_success()); assert!(res3.status().is_success());
let req4 = TestRequest::with_uri("/v1//something").to_request();
let res4 = call_service(&mut app, req4).await;
assert!(res4.status().is_success());
} }
#[actix_rt::test] #[actix_rt::test]
@ -156,6 +173,10 @@ mod tests {
let req3 = TestRequest::with_uri("//v1///something").to_srv_request(); let req3 = TestRequest::with_uri("//v1///something").to_srv_request();
let res3 = normalize.call(req3).await.unwrap(); let res3 = normalize.call(req3).await.unwrap();
assert!(res3.status().is_success()); assert!(res3.status().is_success());
let req4 = TestRequest::with_uri("/v1//something").to_srv_request();
let res4 = normalize.call(req4).await.unwrap();
assert!(res4.status().is_success());
} }
#[actix_rt::test] #[actix_rt::test]
@ -178,11 +199,11 @@ mod tests {
} }
#[actix_rt::test] #[actix_rt::test]
async fn should_normalize_nothing_notrail() { async fn should_normalize_notrail() {
const URI: &str = "/v1/something"; const URI: &str = "/v1/something";
let srv = |req: ServiceRequest| { let srv = |req: ServiceRequest| {
assert_eq!(URI, req.path()); assert_eq!(URI.to_string() + "/", req.path());
ok(req.into_response(HttpResponse::Ok().finish())) ok(req.into_response(HttpResponse::Ok().finish()))
}; };