Skip to content

Commit

Permalink
api/v1: add cache-control header (#1984)
Browse files Browse the repository at this point in the history
* api/v1: add cache-control header

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 <[email protected]>

* api/v1: add missing check

Signed-off-by: Giedrius Statkevičius <[email protected]>

* api/v1: don't store on errs

Signed-off-by: Giedrius Statkevičius <[email protected]>
  • Loading branch information
GiedriusS authored Jan 13, 2020
1 parent f08038b commit 17fd999
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/query/api/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +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")
if len(warnings) > 0 {
w.Header().Set("Cache-Control", "no-store")
}
w.WriteHeader(http.StatusOK)

resp := &response{
Expand All @@ -550,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 {
Expand Down

0 comments on commit 17fd999

Please sign in to comment.