From 7466ee25a8d94017735a0380fc232fd8ec472421 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Thu, 10 Feb 2022 13:57:57 -0500 Subject: [PATCH] Don't send header if it makes no sense to do so. --- src/allmydata/storage/http_server.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index 491fcd39b..f89a156a3 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -329,8 +329,11 @@ class HTTPServer(object): data = bucket.read(offset, end - offset) request.setResponseCode(http.PARTIAL_CONTENT) - request.setHeader( - "content-range", - ContentRange("bytes", offset, offset + len(data)).to_header(), - ) + if len(data): + # For empty bodies the content-range header makes no sense since + # the end of the range is inclusive. + request.setHeader( + "content-range", + ContentRange("bytes", offset, offset + len(data)).to_header(), + ) return data