]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: set Cache-Control header only if presents on error
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 7 Mar 2024 16:57:41 +0000 (23:57 +0700)
committerDamien Neil <dneil@google.com>
Thu, 7 Mar 2024 20:48:58 +0000 (20:48 +0000)
CL 544019 changes http.Error to remove misleading response headers.
However, it also adds new "Cache-Control" header unconditionally, which
may breaks existing clients out there, who do not expect to see the
this header in the response like test in golang.org/x/net/http2.

To keep thing backward compatible, http.Error should only add
Cache-Control header if it has been presented.

Updates #50905

Change-Id: I989e9f999a30ec170df4fb28905f50aed0267dad
Reviewed-on: https://go-review.googlesource.com/c/go/+/569815
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/net/http/server.go

index fa953d842ec156b9e8db7650ab3ef47eb9f0939d..d0e4dc69e5b53e512d9c470d00e7dc5fd748b0d7 100644 (file)
@@ -2181,8 +2181,10 @@ func Error(w ResponseWriter, error string, code int) {
        h.Del("Etag")
        h.Del("Last-Modified")
        // There might be cache control headers set for some other content,
-       // but we reset it to no-cache for the error content.
-       h.Set("Cache-Control", "no-cache")
+       // but we reset it to no-cache for the error content if presents.
+       if h.has("Cache-Control") {
+               h.Set("Cache-Control", "no-cache")
+       }
        // There might be content type already set, but we reset it to
        // text/plain for the error message.
        h.Set("Content-Type", "text/plain; charset=utf-8")