From 3f74e984dfb8d5115e3f1046f2864fe84f8a186e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Fri, 10 Jan 2020 19:36:08 +0200 Subject: [PATCH 1/3] api/v1: add cache-control header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's set `Cache-Control` to `no-store` if there were any warnings while the query was being executed i.e. it is a partial response or we got some other problem. Signed-off-by: Giedrius Statkevičius --- pkg/query/api/v1.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index 17ebc07321..ad4ab5248e 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -536,6 +536,7 @@ func (api *API) series(r *http.Request) (interface{}, []error, *ApiError) { func Respond(w http.ResponseWriter, data interface{}, warnings []error) { w.Header().Set("Content-Type", "application/json") + w.Header().Set("Cache-Control", "no-store") w.WriteHeader(http.StatusOK) resp := &response{ From 5860c3d3b2fba171ef3e607d0b383db4ad2b912c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Fri, 10 Jan 2020 20:04:37 +0200 Subject: [PATCH 2/3] api/v1: add missing check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Giedrius Statkevičius --- pkg/query/api/v1.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index ad4ab5248e..1a2ea3a635 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -536,7 +536,9 @@ func (api *API) series(r *http.Request) (interface{}, []error, *ApiError) { func Respond(w http.ResponseWriter, data interface{}, warnings []error) { w.Header().Set("Content-Type", "application/json") - w.Header().Set("Cache-Control", "no-store") + if len(warnings) > 0 { + w.Header().Set("Cache-Control", "no-store") + } w.WriteHeader(http.StatusOK) resp := &response{ From 8193830b88a257bc2b87f667407f584cf976f587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Fri, 10 Jan 2020 20:05:50 +0200 Subject: [PATCH 3/3] api/v1: don't store on errs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Giedrius Statkevičius --- pkg/query/api/v1.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/query/api/v1.go b/pkg/query/api/v1.go index 1a2ea3a635..0fb1b24b44 100644 --- a/pkg/query/api/v1.go +++ b/pkg/query/api/v1.go @@ -553,6 +553,7 @@ func Respond(w http.ResponseWriter, data interface{}, warnings []error) { func RespondError(w http.ResponseWriter, apiErr *ApiError, data interface{}) { w.Header().Set("Content-Type", "application/json") + w.Header().Set("Cache-Control", "no-store") var code int switch apiErr.Typ {