mirror of
https://github.com/fafhrd91/actix-web
synced 2025-01-18 05:41:50 +01:00
do not override content-length header
This commit is contained in:
parent
07f6ca4b71
commit
4e7fac08b9
@ -176,13 +176,11 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
||||
buffer.extend_from_slice(reason);
|
||||
|
||||
// content length
|
||||
let mut len_is_set = true;
|
||||
match info.length {
|
||||
ResponseLength::Chunked => {
|
||||
buffer.extend_from_slice(b"\r\ntransfer-encoding: chunked\r\n")
|
||||
}
|
||||
ResponseLength::Zero => {
|
||||
buffer.extend_from_slice(b"\r\ncontent-length: 0\r\n")
|
||||
}
|
||||
ResponseLength::Length(len) => {
|
||||
helpers::write_content_length(len, &mut buffer)
|
||||
}
|
||||
@ -191,6 +189,10 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
||||
write!(buffer.writer(), "{}", len)?;
|
||||
buffer.extend_from_slice(b"\r\n");
|
||||
}
|
||||
ResponseLength::Zero => {
|
||||
len_is_set = false;
|
||||
buffer.extend_from_slice(b"\r\n");
|
||||
}
|
||||
ResponseLength::None => buffer.extend_from_slice(b"\r\n"),
|
||||
}
|
||||
if let Some(ce) = info.content_encoding {
|
||||
@ -212,6 +214,9 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
||||
},
|
||||
CONTENT_LENGTH => match info.length {
|
||||
ResponseLength::None => (),
|
||||
ResponseLength::Zero => {
|
||||
len_is_set = true;
|
||||
}
|
||||
_ => continue,
|
||||
},
|
||||
DATE => {
|
||||
@ -248,6 +253,9 @@ impl<T: AsyncWrite, H: 'static> Writer for H1Writer<T, H> {
|
||||
unsafe {
|
||||
buffer.advance_mut(pos);
|
||||
}
|
||||
if !len_is_set {
|
||||
buffer.extend_from_slice(b"content-length: 0\r\n")
|
||||
}
|
||||
|
||||
// optimized date header, set_date writes \r\n
|
||||
if !has_date {
|
||||
|
@ -191,7 +191,6 @@ impl Output {
|
||||
|
||||
let transfer = match resp.body() {
|
||||
Body::Empty => {
|
||||
if !info.head {
|
||||
info.length = match resp.status() {
|
||||
StatusCode::NO_CONTENT
|
||||
| StatusCode::CONTINUE
|
||||
@ -199,7 +198,6 @@ impl Output {
|
||||
| StatusCode::PROCESSING => ResponseLength::None,
|
||||
_ => ResponseLength::Zero,
|
||||
};
|
||||
}
|
||||
*self = Output::Empty(buf);
|
||||
return;
|
||||
}
|
||||
|
@ -1358,8 +1358,8 @@ fn test_ssl_handshake_timeout() {
|
||||
|
||||
#[test]
|
||||
fn test_content_length() {
|
||||
use http::StatusCode;
|
||||
use actix_web::http::header::{HeaderName, HeaderValue};
|
||||
use http::StatusCode;
|
||||
|
||||
let mut srv = test::TestServer::new(move |app| {
|
||||
app.resource("/{status}", |r| {
|
||||
@ -1398,4 +1398,3 @@ fn test_content_length() {
|
||||
assert_eq!(response.headers().get(&header), Some(&value));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user