mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-23 23:51:06 +01:00
Content-Length is 0 for NamedFile HEAD request #914
This commit is contained in:
parent
c8118e8411
commit
bf48798bce
@ -1,8 +1,10 @@
|
|||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
## [0.1.2] - 2019-06-06
|
## [0.1.2] - 2019-06-13
|
||||||
|
|
||||||
* Fix ring dependency from actix-web default features for #741.
|
* Content-Length is 0 for NamedFile HEAD request #914
|
||||||
|
|
||||||
|
* Fix ring dependency from actix-web default features for #741
|
||||||
|
|
||||||
## [0.1.1] - 2019-06-01
|
## [0.1.1] - 2019-06-01
|
||||||
|
|
||||||
|
@ -926,6 +926,29 @@ mod tests {
|
|||||||
assert_eq!(bytes.freeze(), data);
|
assert_eq!(bytes.freeze(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_head_content_length_headers() {
|
||||||
|
let mut srv = test::init_service(
|
||||||
|
App::new().service(Files::new("test", ".").index_file("tests/test.binary")),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Valid range header
|
||||||
|
let request = TestRequest::default()
|
||||||
|
.method(Method::HEAD)
|
||||||
|
.uri("/t%65st/tests/test.binary")
|
||||||
|
.to_request();
|
||||||
|
let response = test::call_service(&mut srv, request);
|
||||||
|
|
||||||
|
let contentlength = response
|
||||||
|
.headers()
|
||||||
|
.get(header::CONTENT_LENGTH)
|
||||||
|
.unwrap()
|
||||||
|
.to_str()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
assert_eq!(contentlength, "100");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_static_files_with_spaces() {
|
fn test_static_files_with_spaces() {
|
||||||
let mut srv = test::init_service(
|
let mut srv = test::init_service(
|
||||||
|
@ -422,20 +422,16 @@ impl Responder for NamedFile {
|
|||||||
return Ok(resp.status(StatusCode::NOT_MODIFIED).finish());
|
return Ok(resp.status(StatusCode::NOT_MODIFIED).finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
if *req.method() == Method::HEAD {
|
let reader = ChunkedReadFile {
|
||||||
Ok(resp.finish())
|
offset,
|
||||||
} else {
|
size: length,
|
||||||
let reader = ChunkedReadFile {
|
file: Some(self.file),
|
||||||
offset,
|
fut: None,
|
||||||
size: length,
|
counter: 0,
|
||||||
file: Some(self.file),
|
};
|
||||||
fut: None,
|
if offset != 0 || length != self.md.len() {
|
||||||
counter: 0,
|
return Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader));
|
||||||
};
|
};
|
||||||
if offset != 0 || length != self.md.len() {
|
Ok(resp.body(SizedStream::new(length, reader)))
|
||||||
return Ok(resp.status(StatusCode::PARTIAL_CONTENT).streaming(reader));
|
|
||||||
};
|
|
||||||
Ok(resp.body(SizedStream::new(length, reader)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user