github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/web/publichandler/cache_handler.go (about)

     1  package publichandler
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/NYTimes/gziphandler"
     8  )
     9  
    10  const yearInSeconds = 31536000
    11  
    12  func CacheNearlyForever(handler http.Handler) http.Handler {
    13  	withoutGz := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    14  		w.Header().Add("Cache-Control", fmt.Sprintf("max-age=%d, private", yearInSeconds))
    15  		handler.ServeHTTP(w, r)
    16  	})
    17  	return gziphandler.GzipHandler(withoutGz)
    18  }