Skip to content

Commit

Permalink
Fix/cache while update (#52)
Browse files Browse the repository at this point in the history
Signed-off-by: orca-zhang <[email protected]>
  • Loading branch information
orca-zhang authored Oct 25, 2024
1 parent e69e612 commit ea4a256
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions route/gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
11 changes: 11 additions & 0 deletions route/static_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/fs"
"net/http"
"os"
"regexp"
"time"

"github.com/IceWhaleTech/CasaOS-Gateway/service"
Expand Down Expand Up @@ -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()))
Expand Down

0 comments on commit ea4a256

Please sign in to comment.