From 4e7bd20f8fdccdb2f0f30b051e3ea3fffb449367 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Fri, 5 Jan 2024 16:10:33 -0800 Subject: net/http: remove Content-Length header in http.Error Error replies to a request with an error message and HTTP code. Delete any preexisting Content-Length header before writing the header; if a Content-Length is present, it's probably for content that the caller has given up on writing. For #50905 Change-Id: Ia3d4ca008be46fa5d41afadf29ca5cacb1c47660 Reviewed-on: https://go-review.googlesource.com/c/go/+/554216 Reviewed-by: Brad Fitzpatrick LUCI-TryBot-Result: Go LUCI Reviewed-by: Jonathan Amsterdam --- src/net/http/server.go | 1 + 1 file changed, 1 insertion(+) (limited to 'src/net/http/server.go') diff --git a/src/net/http/server.go b/src/net/http/server.go index 7d73cca43f..bd7cce6793 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2173,6 +2173,7 @@ func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request) { // writes are done to w. // The error message should be plain text. func Error(w ResponseWriter, error string, code int) { + w.Header().Del("Content-Length") w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(code) -- cgit v1.3-5-g9baa