Make sure HTTP responses are not cacheable.

This commit is contained in:
Mihai Parparita 2014-12-13 15:35:10 -08:00
parent 5b5cf2ab6a
commit 1bf5d997f6

View file

@ -136,6 +136,7 @@ type AppHandler func(http.ResponseWriter, *http.Request) *AppError
func (fn AppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer panicRecovery(w, r)
makeUncacheable(w)
if e := fn(w, r); e != nil {
handleAppError(e, w, r)
}
@ -145,6 +146,7 @@ type SignedInAppHandler func(http.ResponseWriter, *http.Request, *AppSignedInSta
func (fn SignedInAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer panicRecovery(w, r)
makeUncacheable(w)
session, _ := sessionStore.Get(r, sessionConfig.CookieName)
userId, ok := session.Values[sessionConfig.UserIdKey].(int)
if !ok {
@ -181,6 +183,12 @@ func panicRecovery(w http.ResponseWriter, r *http.Request) {
}
}
func makeUncacheable(w http.ResponseWriter) {
w.Header().Set(
"Cache-Control", "no-cache, no-store, max-age=0, must-revalidate")
w.Header().Set("Expires", "0")
}
func handleAppError(e *AppError, w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
if e.Type == AppErrorTypeGitHubFetch {