From f1c3fc48674bd22348aafdea69a09bdb6f847685 Mon Sep 17 00:00:00 2001 From: Maximilian Mader Date: Sun, 1 Aug 2021 21:03:11 +0200 Subject: [PATCH] `actix-files` Do not send a message body in the NOT_MODIFIED case As per 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 : > 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. --- actix-files/src/named.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs index a9b95bad1..7fb0e2a53 100644 --- a/actix-files/src/named.rs +++ b/actix-files/src/named.rs @@ -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 {