Skip to content

Commit

Permalink
Merge pull request #30 from dabooz/issue1174
Browse files Browse the repository at this point in the history
add no cache headers to HTTP responses
  • Loading branch information
dabooz authored Sep 9, 2019
2 parents e203f63 + cc6a972 commit baede44
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions core/base/apiServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ func setupAPIServer() {
}

func handleDestinations(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -283,6 +285,8 @@ func handleDestinations(writer http.ResponseWriter, request *http.Request) {
// schema:
// type: string
func handleResend(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -310,6 +314,8 @@ func handleResend(writer http.ResponseWriter, request *http.Request) {
}

func handleShutdown(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

code, _, _ := security.Authenticate(request)
if code != security.AuthSyncAdmin {
writer.WriteHeader(http.StatusForbidden)
Expand Down Expand Up @@ -357,6 +363,8 @@ func handleShutdown(writer http.ResponseWriter, request *http.Request) {
}

func handleObjects(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -466,6 +474,8 @@ func handleObjects(writer http.ResponseWriter, request *http.Request) {
}

func handleObjectRequest(orgID string, objectType string, objectID string, writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

switch request.Method {

// swagger:operation GET /api/v1/objects/{orgID}/{objectType}/{objectID} handleGetObject
Expand Down Expand Up @@ -1946,6 +1956,8 @@ func handleUpdateObject(orgID string, objectType string, objectID string, writer
// schema:
// type: string
func handleGetOrganizations(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -1990,6 +2002,8 @@ func handleGetOrganizations(writer http.ResponseWriter, request *http.Request) {
}

func handleOrganizations(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -2108,6 +2122,8 @@ func handleOrganizations(writer http.ResponseWriter, request *http.Request) {
}

func handleSecurity(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

if !common.Running {
writer.WriteHeader(http.StatusServiceUnavailable)
return
Expand Down Expand Up @@ -2549,6 +2565,8 @@ type healthReport struct {
// schema:
// type: string
func handleHealth(writer http.ResponseWriter, request *http.Request) {
setCacheControlHeaders(writer)

detailsString := request.URL.Query().Get("details")
details := false
var err error
Expand Down Expand Up @@ -2603,3 +2621,9 @@ func handleHealth(writer http.ResponseWriter, request *http.Request) {
}
}
}

// Set HTTP cache control headers for http 1.0 and 1.1 clients.
func setCacheControlHeaders(writer http.ResponseWriter) {
writer.Header().Set("Cache-Control", "no-store")
writer.Header().Set("Pragma", "no-cache")
}

0 comments on commit baede44

Please sign in to comment.