mirror of
https://github.com/minio/minio.git
synced 2025-04-15 16:39:16 -04:00
browser-caching: enable browser caching for WebUI
This commit is contained in:
parent
b49f21ec82
commit
a344e7713a
@ -93,6 +93,23 @@ func parseDate(req *http.Request) (time.Time, error) {
|
|||||||
return time.Time{}, errors.New("invalid request")
|
return time.Time{}, errors.New("invalid request")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adds Cache-Control header
|
||||||
|
type cacheControlHandler struct {
|
||||||
|
handler http.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func setCacheControlHandler(h http.Handler) http.Handler {
|
||||||
|
return cacheControlHandler{h}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h cacheControlHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "GET" {
|
||||||
|
// expire the cache in one week
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=604800")
|
||||||
|
}
|
||||||
|
h.handler.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
|
|
||||||
// TimeValidityHandler to validate parsable time over http header
|
// TimeValidityHandler to validate parsable time over http header
|
||||||
func TimeValidityHandler(h http.Handler) http.Handler {
|
func TimeValidityHandler(h http.Handler) http.Handler {
|
||||||
return timeHandler{h}
|
return timeHandler{h}
|
||||||
|
@ -55,9 +55,10 @@ type WebAPI struct {
|
|||||||
|
|
||||||
func getWebAPIHandler(web *WebAPI) http.Handler {
|
func getWebAPIHandler(web *WebAPI) http.Handler {
|
||||||
var mwHandlers = []MiddlewareHandler{
|
var mwHandlers = []MiddlewareHandler{
|
||||||
TimeValidityHandler, // Validate time.
|
setCacheControlHandler, // Adds Cache-Control header
|
||||||
AuthHandler, // Authentication handler for verifying tokens.
|
TimeValidityHandler, // Validate time.
|
||||||
CorsHandler, // CORS added only for testing purposes.
|
AuthHandler, // Authentication handler for verifying tokens.
|
||||||
|
CorsHandler, // CORS added only for testing purposes.
|
||||||
}
|
}
|
||||||
if web.AccessLog {
|
if web.AccessLog {
|
||||||
mwHandlers = append(mwHandlers, AccessLogHandler)
|
mwHandlers = append(mwHandlers, AccessLogHandler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user