Skip to content

Commit ea4a256

Browse files
authored
Fix/cache while update (#52)
Signed-off-by: orca-zhang <[email protected]>
1 parent e69e612 commit ea4a256

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

route/gateway_route.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ func rewriteRequestSourceIP(r *http.Request) {
3636
// fix https://github.com/IceWhaleTech/CasaOS/issues/1247
3737
if r.Header.Get("X-Forwarded-For") != "" {
3838
ipList = strings.Split(r.Header.Get("X-Forwarded-For"), ",")
39-
}
4039

41-
// when r.Header.Get("X-Forwarded-For") is "". to clean the ipList.
42-
// fix https://github.com/IceWhaleTech/CasaOS/issues/1247
43-
if len(ipList) == 1 && ipList[0] == "" {
44-
ipList = []string{}
40+
// when r.Header.Get("X-Forwarded-For") is "". to clean the ipList.
41+
// fix https://github.com/IceWhaleTech/CasaOS/issues/1247
42+
if len(ipList) == 1 && ipList[0] == "" {
43+
ipList = []string{}
44+
}
4545
}
4646

4747
r.Header.Del("X-Forwarded-For")

route/static_route.go

+11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/fs"
77
"net/http"
88
"os"
9+
"regexp"
910
"time"
1011

1112
"github.com/IceWhaleTech/CasaOS-Gateway/service"
@@ -95,10 +96,20 @@ func (c *CustomFileInfo) ModTime() time.Time {
9596
return startTime
9697
}
9798

99+
var indexRE = regexp.MustCompile(`/($|modules/[^\/]*/($|(index\.(html?|aspx?|cgi|do|jsp))|((default|index|home)\.php)))`)
100+
98101
func (s *StaticRoute) GetRoute() http.Handler {
99102
e := echo.New()
100103

101104
e.Use(echo_middleware.Gzip())
105+
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
106+
return func(ctx echo.Context) error {
107+
if indexRE.MatchString(ctx.Request().URL.Path) {
108+
ctx.Response().Writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate,proxy-revalidate, max-age=0")
109+
}
110+
return next(ctx)
111+
}
112+
})
102113

103114
// sovle 304 cache problem by 'If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT' from web browser
104115
e.StaticFS("/", NewCustomFS(s.state.GetWWWPath()))

0 commit comments

Comments
 (0)