Skip to content

Commit

Permalink
Merge pull request #2910 from cloudfoundry-incubator/apply-cache-cont…
Browse files Browse the repository at this point in the history
…rol-non-static

Update cache-control header
  • Loading branch information
nwmac authored Aug 24, 2018
2 parents f3df0c6 + 3717766 commit 8e99ca3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/jetstream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,8 @@ func (p *portalProxy) registerRoutes(e *echo.Echo, addSetupMiddleware *setupMidd
pp = e.Group("")
}

pp.Use(p.setSecureCacheContentMiddleware)

// Add middleware to block requests if unconfigured
if addSetupMiddleware.addSetup {
go p.SetupPoller(addSetupMiddleware)
Expand Down Expand Up @@ -730,6 +732,7 @@ func (p *portalProxy) registerRoutes(e *echo.Echo, addSetupMiddleware *setupMidd

// Serve up static resources
if err == nil {
e.Use(p.setStaticCacheContentMiddleware)
log.Debug("Add URL Check Middleware")
e.Use(p.urlCheckMiddleware)
e.Use(middleware.Gzip())
Expand Down
15 changes: 15 additions & 0 deletions src/jetstream/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ func (p *portalProxy) urlCheckMiddleware(h echo.HandlerFunc) echo.HandlerFunc {
}
}

func (p *portalProxy) setStaticCacheContentMiddleware(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
log.Debug("setStaticContentHeadersMiddleware")
c.Response().Header().Set("cache-control", "no-cache")
return h(c)
}
}

func (p *portalProxy) setSecureCacheContentMiddleware(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Set("cache-control", "no-store")
return h(c)
}
}

func (p *portalProxy) adminMiddleware(h echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
// if user is an admin, passthrough request
Expand Down

0 comments on commit 8e99ca3

Please sign in to comment.