mirror of https://github.com/fafhrd91/actix-web
Compare commits
5 Commits
7a092b1485
...
d297d4f6d7
| Author | SHA1 | Date |
|---|---|---|
|
|
d297d4f6d7 | |
|
|
d119500f93 | |
|
|
a3f95ee1ef | |
|
|
bb2c6cebfd | |
|
|
0cb453e499 |
|
|
@ -345,7 +345,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "actix-web"
|
||||
version = "4.11.0"
|
||||
version = "4.12.0"
|
||||
dependencies = [
|
||||
"actix-codec",
|
||||
"actix-files",
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
## 4.12.0
|
||||
|
||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now sets `Content-Type` to `application/octet-stream` if `Content-Type` does not exist.
|
||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now calls `actix_web::response::builder::HttpResponseBuilder::no_chunking()` if `Content-Length` is set by user.
|
||||
- `actix_web::response::builder::HttpResponseBuilder::streaming()` now calls `actix_web::response::builder::HttpResponseBuilder::no_chunking()` and returns `SizedStream` if `Content-Length` is set by user.
|
||||
- Add `ws` crate feature (on-by-default) which forwards to `actix-http` and guards some of its `ResponseError` impls.
|
||||
- Add public export for `EitherExtractError` in `error` module.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "actix-web"
|
||||
version = "4.11.0"
|
||||
version = "4.12.0"
|
||||
description = "Actix Web is a powerful, pragmatic, and extremely fast web framework for Rust"
|
||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>", "Rob Ede <robjtede@icloud.com>"]
|
||||
keywords = ["actix", "http", "web", "framework", "async"]
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
<!-- prettier-ignore-start -->
|
||||
|
||||
[](https://crates.io/crates/actix-web)
|
||||
[](https://docs.rs/actix-web/4.11.0)
|
||||
[](https://docs.rs/actix-web/4.12.0)
|
||||

|
||||

|
||||
[](https://deps.rs/crate/actix-web/4.11.0)
|
||||
[](https://deps.rs/crate/actix-web/4.12.0)
|
||||
<br />
|
||||
[](https://github.com/actix/actix-web/actions/workflows/ci.yml)
|
||||
[](https://codecov.io/gh/actix/actix-web)
|
||||
|
|
|
|||
|
|
@ -110,14 +110,22 @@ where
|
|||
|
||||
#[allow(clippy::borrow_interior_mutable_const)]
|
||||
fn call(&self, req: ServiceRequest) -> Self::Future {
|
||||
if req.extensions().get::<Encoding>().is_some() {
|
||||
return Either::left(CompressResponse {
|
||||
fut: self.service.call(req),
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
}
|
||||
|
||||
// negotiate content-encoding
|
||||
let accept_encoding = req.get_header::<AcceptEncoding>();
|
||||
|
||||
let accept_encoding = match accept_encoding {
|
||||
// missing header; fallback to identity
|
||||
None => {
|
||||
req.extensions_mut().insert::<Encoding>(Encoding::identity());
|
||||
|
||||
return Either::left(CompressResponse {
|
||||
encoding: Encoding::identity(),
|
||||
fut: self.service.call(req),
|
||||
_phantom: PhantomData,
|
||||
})
|
||||
|
|
@ -143,11 +151,14 @@ where
|
|||
.map_into_right_body()))
|
||||
}
|
||||
|
||||
Some(encoding) => Either::left(CompressResponse {
|
||||
Some(encoding) => {
|
||||
req.extensions_mut().insert::<Encoding>(encoding);
|
||||
|
||||
Either::left(CompressResponse {
|
||||
fut: self.service.call(req),
|
||||
encoding,
|
||||
_phantom: PhantomData,
|
||||
}),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -159,7 +170,6 @@ pin_project! {
|
|||
{
|
||||
#[pin]
|
||||
fut: S::Future,
|
||||
encoding: Encoding,
|
||||
_phantom: PhantomData<B>,
|
||||
}
|
||||
}
|
||||
|
|
@ -176,8 +186,19 @@ where
|
|||
|
||||
match ready!(this.fut.poll(cx)) {
|
||||
Ok(resp) => {
|
||||
let enc = match this.encoding {
|
||||
Encoding::Known(enc) => *enc,
|
||||
let request_encoding = resp.request().extensions().get::<Encoding>().cloned();
|
||||
|
||||
let encoding = match request_encoding {
|
||||
Some(enc) => enc.clone(),
|
||||
None => {
|
||||
return Poll::Ready(Ok(resp.map_body(move |head, body| {
|
||||
EitherBody::left(Encoder::response(ContentEncoding::Identity, head, body))
|
||||
})));
|
||||
}
|
||||
};
|
||||
|
||||
let enc = match encoding {
|
||||
Encoding::Known(enc) => enc,
|
||||
Encoding::Unknown(enc) => {
|
||||
unimplemented!("encoding '{enc}' should not be here");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use futures_core::Stream;
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::{
|
||||
body::{BodyStream, BoxBody, MessageBody},
|
||||
body::{BodyStream, BoxBody, MessageBody, SizedStream},
|
||||
dev::Extensions,
|
||||
error::{Error, JsonPayloadError},
|
||||
http::{
|
||||
|
|
@ -335,18 +335,19 @@ impl HttpResponseBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(parts) = self.inner() {
|
||||
if let Some(length) = parts.headers.get(header::CONTENT_LENGTH) {
|
||||
if let Ok(length) = length.to_str() {
|
||||
if let Ok(length) = length.parse::<u64>() {
|
||||
self.no_chunking(length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let content_length = self
|
||||
.inner()
|
||||
.and_then(|parts| parts.headers.get(header::CONTENT_LENGTH))
|
||||
.and_then(|value| value.to_str().ok())
|
||||
.and_then(|value| value.parse::<u64>().ok());
|
||||
|
||||
if let Some(len) = content_length {
|
||||
self.no_chunking(len);
|
||||
self.body(SizedStream::new(len, stream))
|
||||
} else {
|
||||
self.body(BodyStream::new(stream))
|
||||
}
|
||||
}
|
||||
|
||||
/// Set a JSON body and build the `HttpResponse`.
|
||||
///
|
||||
|
|
|
|||
Loading…
Reference in New Issue