Files
EdgeCommon/pkg/serverconfigs/http_page_optimization_base.go

64 lines
1.3 KiB
Go
Raw Normal View History

2024-07-27 13:29:26 +08:00
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package serverconfigs
import (
"strings"
2024-07-27 13:29:26 +08:00
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
)
type HTTPBaseOptimizationConfig struct {
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
}
func (this *HTTPBaseOptimizationConfig) Init() error {
// only url
for _, pattern := range this.OnlyURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
// except url
for _, pattern := range this.ExceptURLPatterns {
err := pattern.Init()
if err != nil {
return err
}
}
return nil
}
func (this *HTTPBaseOptimizationConfig) MatchURL(url string) bool {
// 去除问号
var index = strings.Index(url, "?")
if index >= 0 {
url = url[:index]
}
// except
if len(this.ExceptURLPatterns) > 0 {
for _, pattern := range this.ExceptURLPatterns {
if pattern.Match(url) {
return false
}
}
}
// only
if len(this.OnlyURLPatterns) > 0 {
for _, pattern := range this.OnlyURLPatterns {
if pattern.Match(url) {
return true
}
}
return false
}
return true
}