mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-03-25 09:25:49 +00:00
Make sure HTTP responses are not cacheable.
This commit is contained in:
parent
5b5cf2ab6a
commit
1bf5d997f6
1 changed files with 8 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue