Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -1727,19 +1727,28 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
location.UpdateDirective("proxy_pass", []string{req.ProxyPass})
location.UpdateDirective("proxy_set_header", []string{"Host", req.ProxyHost})
location.ChangePath(req.Modifier, req.Match)
// Server Cache Settings
if req.Cache {
if err = openProxyCache(website); err != nil {
return
}
location.AddCache(req.CacheTime, req.CacheUnit, fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias), req.ServerCacheTime, req.ServerCacheUnit)
location.AddServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias), req.ServerCacheTime, req.ServerCacheUnit)
} else {
location.RemoveCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
location.RemoveServerCache(fmt.Sprintf("proxy_cache_zone_of_%s", website.Alias))
}
// Browser Cache Settings
if req.CacheTime != 0 {
location.AddBrowserCache(req.CacheTime, req.CacheUnit)
} else {
location.RemoveBrowserCache()
}
// Content Replace Settings
if len(req.Replaces) > 0 {
location.AddSubFilter(req.Replaces)
} else {
location.RemoveSubFilter()
}
// SSL Settings
if req.SNI {
location.UpdateDirective("proxy_ssl_server_name", []string{"on"})
if req.ProxySSLName != "" {
Expand All @@ -1748,6 +1757,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
} else {
location.UpdateDirective("proxy_ssl_server_name", []string{"off"})
}
// CORS Settings
if req.Cors {
location.UpdateDirective("add_header", []string{"Access-Control-Allow-Origin", req.AllowOrigins, "always"})
if req.AllowMethods != "" {
Expand All @@ -1768,7 +1778,7 @@ func (w WebsiteService) OperateProxy(req request.WebsiteProxyConfig) (err error)
if req.Preflight {
location.AddCorsOption()
} else {
location.RemoveDirectiveByFullParams("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"})
location.RemoveCorsOption()
}
} else {
location.RemoveDirective("add_header", []string{"Access-Control-Allow-Origin"})
Expand Down
33 changes: 23 additions & 10 deletions agent/utils/nginx/components/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func (l *Location) ChangePath(Modifier string, Match string) {
l.Match = Match
}

func (l *Location) AddCache(cacheTime int, cacheUint, cacheKey string, serverCacheTime int, serverCacheUint string) {
func (l *Location) AddBrowserCache(cacheTime int, cacheUint string) {
l.RemoveDirective("add_header", []string{"Cache-Control", "no-cache"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
Expand All @@ -271,28 +271,36 @@ func (l *Location) AddCache(cacheTime int, cacheUint, cacheKey string, serverCac
newDir.Block = block
directives = append(directives, newDir)
l.Directives = directives
l.CacheTime = cacheTime
l.CacheUint = cacheUint
}

func (l *Location) AddServerCache(cacheKey string, serverCacheTime int, serverCacheUint string) {
l.UpdateDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"})
l.UpdateDirective("proxy_cache", []string{cacheKey})
l.UpdateDirective("proxy_cache_key", []string{"$host$uri$is_args$args"})
l.UpdateDirective("proxy_cache_valid", []string{"200", "304", "301", "302", strconv.Itoa(serverCacheTime) + serverCacheUint})
l.Cache = true
l.CacheTime = cacheTime
l.CacheUint = cacheUint
l.ServerCacheTime = serverCacheTime
l.ServerCacheUint = serverCacheUint
}

func (l *Location) RemoveCache(cacheKey string) {
func (l *Location) RemoveBrowserCache() {
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2)$"`, ")"})
l.RemoveDirectiveByFullParams("if", []string{"(", "$uri", "~*", `"\.(gif|png|jpg|css|js|woff|woff2|jpeg|svg|webp|avif)$"`, ")"})
l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie"})
l.RemoveDirective("proxy_cache", []string{cacheKey})
l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"})
l.RemoveDirective("proxy_cache_valid", []string{"200"})

l.UpdateDirective("add_header", []string{"Cache-Control", "no-cache"})

l.CacheTime = 0
l.CacheUint = ""
}

func (l *Location) RemoveServerCache(cacheKey string) {
l.RemoveDirective("proxy_ignore_headers", []string{"Set-Cookie", "Cache-Control", "expires"})
l.RemoveDirective("proxy_cache", []string{cacheKey})
l.RemoveDirective("proxy_cache_key", []string{"$host$uri$is_args$args"})
l.RemoveDirective("proxy_cache_valid", []string{"200"})
l.Cache = false
l.ServerCacheTime = 0
l.ServerCacheUint = ""
}

func (l *Location) AddSubFilter(subFilters map[string]string) {
Expand All @@ -315,6 +323,7 @@ func (l *Location) RemoveSubFilter() {
}

func (l *Location) AddCorsOption() {
l.RemoveCorsOption()
newDir := &Directive{
Name: "if",
Parameters: []string{"(", "$request_method", "=", "'OPTIONS'", ")"},
Expand Down Expand Up @@ -342,3 +351,7 @@ func (l *Location) AddCorsOption() {
directives = append(directives, newDir)
l.Directives = directives
}

func (l *Location) RemoveCorsOption() {
l.RemoveDirectiveByFullParams("if", []string{"(", "$request_method", "=", "'OPTIONS'", ")"})
}
1 change: 1 addition & 0 deletions frontend/src/api/interface/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ export namespace Website {
allowHeaders: string;
allowCredentials: boolean;
preflight: boolean;
browserCache?: boolean;
}

export interface ProxReplace {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,8 @@ const message = {
'The password is asymmetrically encrypted and cannot be echoed. Editing needs to reset the password',
antiLeech: 'Anti-leech',
extends: 'Extension',
browserCache: 'Cache',
browserCache: 'Browser Cache',
serverCache: 'Server Cache',
leechLog: 'Record anti-leech log',
accessDomain: 'Allowed domains',
leechReturn: 'Response resource',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2481,6 +2481,7 @@ const message = {
antiLeech: 'Anti-hotlink',
extends: 'Extensiones',
browserCache: 'Caché de navegador',
serverCache: 'Caché del servidor',
leechLog: 'Registrar logs anti-hotlink',
accessDomain: 'Dominios permitidos',
leechReturn: 'Recurso de respuesta',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,7 @@ const message = {
antiLeech: '反リーチ',
extends: '拡大',
browserCache: 'キャッシュ',
serverCache: 'サーバーキャッシュ',
leechLog: '反リーチログを記録します',
accessDomain: '許可されたドメイン',
leechReturn: '応答リソース',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2365,6 +2365,7 @@ const message = {
antiLeech: '링크 차단',
extends: '확장',
browserCache: '캐시',
serverCache: '서버 캐시',
leechLog: '링크 차단 로그 기록',
accessDomain: '허용된 도메인',
leechReturn: '응답 리소스',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2465,6 +2465,7 @@ const message = {
antiLeech: 'Anti-leech',
extends: 'Pelanjutan',
browserCache: 'Cache',
serverCache: 'Cache Pelayan',
leechLog: 'Rekod log anti-leech',
accessDomain: 'Domain yang dibenarkan',
leechReturn: 'Sumber tindak balas',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,7 @@ const message = {
antiLeech: 'Anti-leech',
extends: 'Extensão',
browserCache: 'Cache',
serverCache: 'Cache do servidor',
leechLog: 'Registrar log anti-leech',
accessDomain: 'Domínios permitidos',
leechReturn: 'Recurso de resposta',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,7 @@ const message = {
antiLeech: 'Анти-лич',
extends: 'Расширение',
browserCache: 'Кэш',
serverCache: 'Кэш сервера',
leechLog: 'Записывать лог анти-лича',
accessDomain: 'Разрешенные домены',
leechReturn: 'Ответ ресурса',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,7 @@ const message = {
antiLeech: 'Sömürü karşıtı',
extends: 'Uzantı',
browserCache: 'Önbellek',
serverCache: 'Sunucu önbelleği',
leechLog: 'Sömürü karşıtı günlüğü kaydet',
accessDomain: 'İzin verilen alan adları',
leechReturn: 'Yanıt kaynağı',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,7 @@ const message = {
antiLeech: '防盜鏈',
extends: '副檔名',
browserCache: '瀏覽器快取',
serverCache: '伺服器快取',
leechLog: '記錄防盜鏈日誌',
accessDomain: '允許的域名',
leechReturn: '響應資源',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,7 @@ const message = {
antiLeech: '防盗链',
extends: '扩展名',
browserCache: '浏览器缓存',
serverCache: '服务器缓存',
leechLog: '记录防盗链日志',
accessDomain: '允许的域名',
leechReturn: '响应资源',
Expand Down
Loading
Loading