37 Star 411 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
cache.go 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
Dan Ramich 提交于 2019-02-15 16:15 . Add Frame-Options header
package responsewriter
import (
"net/http"
"strings"
"github.com/gorilla/mux"
)
func CacheMiddleware(suffixes ...string) mux.MiddlewareFunc {
return mux.MiddlewareFunc(func(handler http.Handler) http.Handler {
return Cache(handler, suffixes...)
})
}
func Cache(handler http.Handler, suffixes ...string) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
i := strings.LastIndex(r.URL.Path, ".")
if i >= 0 {
for _, suffix := range suffixes {
if suffix == r.URL.Path[i+1:] {
w.Header().Set("Cache-Control", "max-age=31536000, public")
}
}
}
handler.ServeHTTP(w, r)
})
}
func NoCache(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
handler.ServeHTTP(w, r)
})
}
func DenyFrameOptions(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Frame-Options", "deny")
handler.ServeHTTP(w, r)
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.6-rc3

搜索帮助

0d507c66 1850385 C8b1a773 1850385