From 06322bd6273a7fa55690e717c60543e5ebf3f5c7 Mon Sep 17 00:00:00 2001
From: fakeshadow <24548779@qq.com>
Date: Mon, 28 Sep 2020 01:15:38 +0800
Subject: [PATCH] remove MessageBody bound generic type from more types
---
CHANGES.md | 8 ++++-
actix-http/src/encoding/encoder.rs | 12 ++++----
actix-http/src/response.rs | 5 ++-
src/app.rs | 31 ++++++++-----------
src/app_service.rs | 49 +++++++++---------------------
src/middleware/compress.rs | 12 ++++----
src/middleware/logger.rs | 17 ++++++-----
7 files changed, 60 insertions(+), 74 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 93a285bfe..7ee62626e 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -2,9 +2,15 @@
## Unreleased - 2020-xx-xx
### Changed
-* remove generic type `B` for `app::App` and it's not bound to `actix_http::body::MessageBody` trait anymore. [#1692]
+* Remove generic type `B` for `app::App`, `app_service::{AppInit, AppInitResult, AppInitService}`.
+ Change `middleware::{Compressed, Logger}` to return `ServiceResponse
` directly. [#1692]
+* Add `TrailingSlash::MergeOnly` behaviour to `NormalizePath`, which allow `NormalizePath`
+ to keep the trailing slash's existance as it is. [#1695]
+* Fix `ResourceMap` recursive references when printing/debugging. [#1708]
[#1692]: https://github.com/actix/actix-web/pull/1692
+[#1695]: https://github.com/actix/actix-web/pull/1695
+[#1708]: https://github.com/actix/actix-web/pull/1708
## 3.0.2 - 2020-09-15
diff --git a/actix-http/src/encoding/encoder.rs b/actix-http/src/encoding/encoder.rs
index eb1821285..2d8cf519e 100644
--- a/actix-http/src/encoding/encoder.rs
+++ b/actix-http/src/encoding/encoder.rs
@@ -29,12 +29,12 @@ pub struct Encoder {
fut: Option>,
}
-impl Encoder {
+impl Encoder {
pub fn response(
encoding: ContentEncoding,
head: &mut ResponseHead,
body: ResponseBody,
- ) -> ResponseBody> {
+ ) -> ResponseBody {
let can_encode = !(head.headers().contains_key(&CONTENT_ENCODING)
|| head.status == StatusCode::SWITCHING_PROTOCOLS
|| head.status == StatusCode::NO_CONTENT
@@ -62,20 +62,20 @@ impl Encoder {
if let Some(enc) = ContentEncoder::encoder(encoding) {
update_head(encoding, head);
head.no_chunking(false);
- return ResponseBody::Body(Encoder {
+ return ResponseBody::Other(Body::from_message(Encoder {
body,
eof: false,
fut: None,
encoder: Some(enc),
- });
+ }));
}
}
- ResponseBody::Body(Encoder {
+ ResponseBody::Other(Body::from_message(Encoder {
body,
eof: false,
fut: None,
encoder: None,
- })
+ }))
}
}
diff --git a/actix-http/src/response.rs b/actix-http/src/response.rs
index 2def67168..b96293a0d 100644
--- a/actix-http/src/response.rs
+++ b/actix-http/src/response.rs
@@ -232,7 +232,10 @@ impl Response {
}
/// Set a body and return previous body value
- pub(crate) fn replace_body(self, body: B2) -> (Response, ResponseBody) {
+ pub(crate) fn replace_body(
+ self,
+ body: B2,
+ ) -> (Response, ResponseBody) {
(
Response {
head: self.head,
diff --git a/src/app.rs b/src/app.rs
index cefd36869..13a25326d 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -3,7 +3,6 @@ use std::fmt;
use std::future::Future;
use std::rc::Rc;
-use actix_http::body::MessageBody;
use actix_http::Extensions;
use actix_service::boxed::{self, BoxServiceFactory};
use actix_service::{
@@ -27,7 +26,7 @@ type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Err
/// Application builder - structure that follows the builder pattern
/// for building application instances.
-pub struct App {
+pub struct App {
endpoint: T,
services: Vec>,
default: Option>,
@@ -38,7 +37,7 @@ pub struct App {
extensions: Extensions,
}
-impl App {
+impl App {
/// Create application builder. Application can be configured with a builder-like pattern.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
@@ -56,13 +55,12 @@ impl App {
}
}
-impl App
+impl App
where
- B: MessageBody,
T: ServiceFactory<
Config = (),
Request = ServiceRequest,
- Response = ServiceResponse,
+ Response = ServiceResponse,
Error = Error,
InitError = (),
>,
@@ -344,14 +342,14 @@ where
/// .route("/index.html", web::get().to(index));
/// }
/// ```
- pub fn wrap(
+ pub fn wrap(
self,
mw: M,
) -> App<
impl ServiceFactory<
Config = (),
Request = ServiceRequest,
- Response = ServiceResponse,
+ Response = ServiceResponse,
Error = Error,
InitError = (),
>,
@@ -360,11 +358,10 @@ where
M: Transform<
T::Service,
Request = ServiceRequest,
- Response = ServiceResponse,
+ Response = ServiceResponse,
Error = Error,
InitError = (),
>,
- B1: MessageBody,
{
App {
endpoint: apply(mw, self.endpoint),
@@ -409,22 +406,21 @@ where
/// .route("/index.html", web::get().to(index));
/// }
/// ```
- pub fn wrap_fn(
+ pub fn wrap_fn(
self,
mw: F,
) -> App<
impl ServiceFactory<
Config = (),
Request = ServiceRequest,
- Response = ServiceResponse,
+ Response = ServiceResponse,
Error = Error,
InitError = (),
>,
>
where
- B1: MessageBody,
F: FnMut(ServiceRequest, &mut T::Service) -> R + Clone,
- R: Future