mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 05:00:24 +08:00 
			
		
		
		
	内容压缩功能增加“例外URL“和“限制URL”设置
This commit is contained in:
		@@ -41,6 +41,9 @@ type HTTPCompressionConfig struct {
 | 
			
		||||
	Conds                *shared.HTTPRequestCondsConfig `yaml:"conds" json:"conds"`                               // 匹配条件
 | 
			
		||||
	EnablePartialContent bool                           `yaml:"enablePartialContent" json:"enablePartialContent"` // 支持PartialContent压缩
 | 
			
		||||
 | 
			
		||||
	OnlyURLPatterns   []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"`     // 仅限的URL
 | 
			
		||||
	ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
 | 
			
		||||
 | 
			
		||||
	minLength        int64
 | 
			
		||||
	maxLength        int64
 | 
			
		||||
	mimeTypeRules    []*shared.MimeTypeRule
 | 
			
		||||
@@ -151,6 +154,21 @@ func (this *HTTPCompressionConfig) Init() error {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// url patterns
 | 
			
		||||
	for _, pattern := range this.ExceptURLPatterns {
 | 
			
		||||
		err := pattern.Init()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, pattern := range this.OnlyURLPatterns {
 | 
			
		||||
		err := pattern.Init()
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -279,3 +297,26 @@ func (this *HTTPCompressionConfig) MatchAcceptEncoding(acceptEncodings string) (
 | 
			
		||||
 | 
			
		||||
	return "", "", false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *HTTPCompressionConfig) MatchURL(url string) bool {
 | 
			
		||||
	// 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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user