mirror of
https://github.com/golang/go
synced 2024-11-17 03:14:50 -07:00
net/http: set Cache-Control header only if presents on error
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>
This commit is contained in:
parent
8d3703ed77
commit
cb733da42c
@ -2181,8 +2181,10 @@ func Error(w ResponseWriter, error string, code int) {
|
|||||||
h.Del("Etag")
|
h.Del("Etag")
|
||||||
h.Del("Last-Modified")
|
h.Del("Last-Modified")
|
||||||
// There might be cache control headers set for some other content,
|
// There might be cache control headers set for some other content,
|
||||||
// but we reset it to no-cache for the error content.
|
// but we reset it to no-cache for the error content if presents.
|
||||||
h.Set("Cache-Control", "no-cache")
|
if h.has("Cache-Control") {
|
||||||
|
h.Set("Cache-Control", "no-cache")
|
||||||
|
}
|
||||||
// There might be content type already set, but we reset it to
|
// There might be content type already set, but we reset it to
|
||||||
// text/plain for the error message.
|
// text/plain for the error message.
|
||||||
h.Set("Content-Type", "text/plain; charset=utf-8")
|
h.Set("Content-Type", "text/plain; charset=utf-8")
|
||||||
|
Loading…
Reference in New Issue
Block a user