mirror of https://github.com/fafhrd91/actix-web
`actix-files` Do not send a message body in the NOT_MODIFIED case
As per RFC7230 section 3.3.2 <https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2>: > A server MAY send a Content-Length header field in a 304 (Not > Modified) response to a conditional GET request (Section 4.1 of > [RFC7232]); > a server MUST NOT send Content-Length in such a response > unless its field-value equals the decimal number of octets that would > have been sent in the payload body of a 200 (OK) response to the same > request. And per RFC7232 section 4.1 <https://datatracker.ietf.org/doc/html/rfc7232#section-4.1>: > A 304 response cannot contain a message-body; it is always terminated > by the first empty line after the header fields. Previously a `Content-Length: 0` header was sent because `.finish()` sets the body to `Body::Empty`, which indicates a zero-sized response.
This commit is contained in:
parent
24d525d978
commit
f1c3fc4867
|
@ -8,7 +8,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
|
|||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
use actix_web::{
|
||||
dev::{BodyEncoding, SizedStream},
|
||||
dev::{Body, BodyEncoding, SizedStream},
|
||||
http::{
|
||||
header::{
|
||||
self, Charset, ContentDisposition, DispositionParam, DispositionType,
|
||||
|
@ -421,7 +421,7 @@ impl NamedFile {
|
|||
if precondition_failed {
|
||||
return Ok(resp.status(StatusCode::PRECONDITION_FAILED).finish());
|
||||
} else if not_modified {
|
||||
return Ok(resp.status(StatusCode::NOT_MODIFIED).finish());
|
||||
return Ok(resp.status(StatusCode::NOT_MODIFIED).body(Body::None));
|
||||
}
|
||||
|
||||
let reader = ChunkedReadFile {
|
||||
|
|
Loading…
Reference in New Issue