Skip to content

Commit db2b38e

Browse files
authored
fix: update browser cache handling in website proxy service (#11762)
* fix: update browser cache handling in website proxy service - Adjusted cache time condition to allow for negative values, introducing a no-cache option. - Updated TypeScript interface to specify browser cache options as 'enable', 'disable', or 'noModify' for better clarity. * refactor: clean up imports and enhance browser cache comments in website proxy service - Removed unused import statements for better code clarity. - Added detailed comments to clarify the behavior of the cache time settings in the OperateProxy function.
1 parent 9303ee3 commit db2b38e

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

agent/app/service/website_proxy.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7+
"path"
8+
"strconv"
9+
"strings"
10+
711
"github.com/1Panel-dev/1Panel/agent/app/dto"
812
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
913
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
@@ -17,9 +21,6 @@ import (
1721
"github.com/1Panel-dev/1Panel/agent/utils/nginx/components"
1822
"github.com/1Panel-dev/1Panel/agent/utils/nginx/parser"
1923
"github.com/1Panel-dev/1Panel/agent/utils/re"
20-
"path"
21-
"strconv"
22-
"strings"
2324
)
2425

2526
func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) {
@@ -119,8 +120,13 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
119120
location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
120121
}
121122
// Browser Cache Settings
122-
if req.CacheTime != 0 {
123+
// cacheTime > 0: enable expires;
124+
// cacheTime == 0: use upstream cache-control, remove self-set;
125+
// cacheTime < 0: force no-cache
126+
if req.CacheTime > 0 {
123127
location.AddBrowserCache(req.CacheTime, req.CacheUnit)
128+
} else if req.CacheTime < 0 {
129+
location.AddBroswerNoCache()
124130
} else {
125131
location.RemoveBrowserCache()
126132
}

frontend/src/api/interface/website.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export namespace Website {
445445
allowHeaders: string;
446446
allowCredentials: boolean;
447447
preflight: boolean;
448-
browserCache?: boolean;
448+
browserCache?: 'enable' | 'disable' | 'noModify';
449449
}
450450

451451
export interface ProxReplace {

0 commit comments

Comments
 (0)