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.
This commit is contained in:
KOMATA
2026-02-02 11:14:30 +08:00
committed by GitHub
parent 9303ee399f
commit db2b38eedb
2 changed files with 11 additions and 5 deletions
+10 -4
View File
@@ -4,6 +4,10 @@ import (
"bytes"
"errors"
"fmt"
"path"
"strconv"
"strings"
"github.com/1Panel-dev/1Panel/agent/app/dto"
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
@@ -17,9 +21,6 @@ import (
"github.com/1Panel-dev/1Panel/agent/utils/nginx/components"
"github.com/1Panel-dev/1Panel/agent/utils/nginx/parser"
"github.com/1Panel-dev/1Panel/agent/utils/re"
"path"
"strconv"
"strings"
)
func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error) {
@@ -119,8 +120,13 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
}
// Browser Cache Settings
if req.CacheTime != 0 {
// cacheTime > 0: enable expires;
// cacheTime == 0: use upstream cache-control, remove self-set;
// cacheTime < 0: force no-cache
if req.CacheTime > 0 {
location.AddBrowserCache(req.CacheTime, req.CacheUnit)
} else if req.CacheTime < 0 {
location.AddBroswerNoCache()
} else {
location.RemoveBrowserCache()
}
+1 -1
View File
@@ -445,7 +445,7 @@ export namespace Website {
allowHeaders: string;
allowCredentials: boolean;
preflight: boolean;
browserCache?: boolean;
browserCache?: 'enable' | 'disable' | 'noModify';
}
export interface ProxReplace {