From d6b0e0ff1c3807edcf82ee95129cb55a5e7fd915 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Thu, 5 Sep 2024 20:31:28 -0400 Subject: [PATCH] Remove "Content-Length" header if http.Error is issued (#5981) --- weed/server/common.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/weed/server/common.go b/weed/server/common.go index e6f6cdb88..5dad9d81b 100644 --- a/weed/server/common.go +++ b/weed/server/common.go @@ -303,11 +303,13 @@ func ProcessRangeRequest(r *http.Request, w http.ResponseWriter, totalSize int64 writeFn, err := prepareWriteFn(0, totalSize) if err != nil { glog.Errorf("ProcessRangeRequest: %v", err) + w.Header().Del("Content-Length") http.Error(w, err.Error(), http.StatusInternalServerError) return fmt.Errorf("ProcessRangeRequest: %v", err) } if err = writeFn(bufferedWriter); err != nil { glog.Errorf("ProcessRangeRequest: %v", err) + w.Header().Del("Content-Length") http.Error(w, err.Error(), http.StatusInternalServerError) return fmt.Errorf("ProcessRangeRequest: %v", err) } @@ -351,6 +353,7 @@ func ProcessRangeRequest(r *http.Request, w http.ResponseWriter, totalSize int64 writeFn, err := prepareWriteFn(ra.start, ra.length) if err != nil { glog.Errorf("ProcessRangeRequest range[0]: %+v err: %v", w.Header(), err) + w.Header().Del("Content-Length") http.Error(w, err.Error(), http.StatusInternalServerError) return fmt.Errorf("ProcessRangeRequest: %v", err) } @@ -358,6 +361,7 @@ func ProcessRangeRequest(r *http.Request, w http.ResponseWriter, totalSize int64 err = writeFn(bufferedWriter) if err != nil { glog.Errorf("ProcessRangeRequest range[0]: %+v err: %v", w.Header(), err) + w.Header().Del("Content-Length") http.Error(w, err.Error(), http.StatusInternalServerError) return fmt.Errorf("ProcessRangeRequest range[0]: %v", err) }