diff --git a/route/gateway_route.go b/route/gateway_route.go index 4dc5767..9bd7fb7 100644 --- a/route/gateway_route.go +++ b/route/gateway_route.go @@ -36,12 +36,12 @@ func rewriteRequestSourceIP(r *http.Request) { // fix https://github.com/IceWhaleTech/CasaOS/issues/1247 if r.Header.Get("X-Forwarded-For") != "" { ipList = strings.Split(r.Header.Get("X-Forwarded-For"), ",") - } - // when r.Header.Get("X-Forwarded-For") is "". to clean the ipList. - // fix https://github.com/IceWhaleTech/CasaOS/issues/1247 - if len(ipList) == 1 && ipList[0] == "" { - ipList = []string{} + // when r.Header.Get("X-Forwarded-For") is "". to clean the ipList. + // fix https://github.com/IceWhaleTech/CasaOS/issues/1247 + if len(ipList) == 1 && ipList[0] == "" { + ipList = []string{} + } } r.Header.Del("X-Forwarded-For") diff --git a/route/static_route.go b/route/static_route.go index 2a3d741..a87c6e9 100644 --- a/route/static_route.go +++ b/route/static_route.go @@ -6,6 +6,7 @@ import ( "io/fs" "net/http" "os" + "regexp" "time" "github.com/IceWhaleTech/CasaOS-Gateway/service" @@ -95,10 +96,20 @@ func (c *CustomFileInfo) ModTime() time.Time { return startTime } +var indexRE = regexp.MustCompile(`/($|modules/[^\/]*/($|(index\.(html?|aspx?|cgi|do|jsp))|((default|index|home)\.php)))`) + func (s *StaticRoute) GetRoute() http.Handler { e := echo.New() e.Use(echo_middleware.Gzip()) + e.Use(func(next echo.HandlerFunc) echo.HandlerFunc { + return func(ctx echo.Context) error { + if indexRE.MatchString(ctx.Request().URL.Path) { + ctx.Response().Writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate,proxy-revalidate, max-age=0") + } + return next(ctx) + } + }) // sovle 304 cache problem by 'If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT' from web browser e.StaticFS("/", NewCustomFS(s.state.GetWWWPath()))