自定义页面增加例外URL和限制URL设置

This commit is contained in:
刘祥超
2023-11-13 10:45:23 +08:00
parent f0b5f6ed76
commit 30ff3ecde5
4 changed files with 125 additions and 37 deletions

View File

@@ -28,7 +28,6 @@ func FindAllHTTPPageBodyTypes() []*shared.Definition {
}
// HTTPPageConfig 特殊页面配置
// TODO 需要支持Header定义
type HTTPPageConfig struct {
Id int64 `yaml:"id" json:"id"` // 页面ID
IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 TODO
@@ -39,6 +38,9 @@ type HTTPPageConfig struct {
URL string `yaml:"url" json:"url"` // URL
Body string `yaml:"body" json:"body"` // 输出的内容
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
statusList []*WildcardStatus
hasStatusList bool
}
@@ -57,6 +59,21 @@ func (this *HTTPPageConfig) Init() error {
this.statusList = append(this.statusList, NewWildcardStatus(s))
}
this.hasStatusList = len(this.statusList) > 0
for _, urlPattern := range this.OnlyURLPatterns {
err := urlPattern.Init()
if err != nil {
return err
}
}
for _, urlPattern := range this.ExceptURLPatterns {
err := urlPattern.Init()
if err != nil {
return err
}
}
return nil
}
@@ -72,3 +89,25 @@ func (this *HTTPPageConfig) Match(status int) bool {
}
return false
}
func (this *HTTPPageConfig) MatchURL(url string) bool {
// except
if len(this.ExceptURLPatterns) > 0 {
for _, pattern := range this.ExceptURLPatterns {
if pattern.Match(url) {
return false
}
}
}
if len(this.OnlyURLPatterns) > 0 {
for _, pattern := range this.OnlyURLPatterns {
if pattern.Match(url) {
return true
}
}
return false
}
return true
}