Просмотр исходного кода

api: add no cache headers for IE11

Adds pragma and expires headers for API calls so that IE11 does not
cache GET calls. Ref #5356
Daniel Lee 8 лет назад
Родитель
Сommit
e6f9546a7c
2 измененных файлов с 4 добавлено и 0 удалено
  1. 2 0
      pkg/middleware/middleware.go
  2. 2 0
      pkg/middleware/middleware_test.go

+ 2 - 0
pkg/middleware/middleware.go

@@ -250,6 +250,8 @@ func AddDefaultResponseHeaders() macaron.Handler {
 	return func(ctx *Context) {
 	return func(ctx *Context) {
 		if ctx.IsApiRequest() && ctx.Req.Method == "GET" {
 		if ctx.IsApiRequest() && ctx.Req.Method == "GET" {
 			ctx.Resp.Header().Add("Cache-Control", "no-cache")
 			ctx.Resp.Header().Add("Cache-Control", "no-cache")
+			ctx.Resp.Header().Add("Pragma", "no-cache")
+			ctx.Resp.Header().Add("Expires", "-1")
 		}
 		}
 	}
 	}
 }
 }

+ 2 - 0
pkg/middleware/middleware_test.go

@@ -33,6 +33,8 @@ func TestMiddlewareContext(t *testing.T) {
 		middlewareScenario("middleware should add Cache-Control header for GET requests to API", func(sc *scenarioContext) {
 		middlewareScenario("middleware should add Cache-Control header for GET requests to API", func(sc *scenarioContext) {
 			sc.fakeReq("GET", "/api/search").exec()
 			sc.fakeReq("GET", "/api/search").exec()
 			So(sc.resp.Header().Get("Cache-Control"), ShouldEqual, "no-cache")
 			So(sc.resp.Header().Get("Cache-Control"), ShouldEqual, "no-cache")
+			So(sc.resp.Header().Get("Pragma"), ShouldEqual, "no-cache")
+			So(sc.resp.Header().Get("Expires"), ShouldEqual, "-1")
 		})
 		})
 
 
 		middlewareScenario("middleware should not add Cache-Control header to for non-API GET requests", func(sc *scenarioContext) {
 		middlewareScenario("middleware should not add Cache-Control header to for non-API GET requests", func(sc *scenarioContext) {