mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-04-24 14:55:18 +08:00
实现HTTP部分功能
This commit is contained in:
@@ -5,3 +5,7 @@ type HTTPHeaderPolicyRef struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
HeaderPolicyId int64 `yaml:"headerPolicyId" json:"headerPolicyId"`
|
||||
}
|
||||
|
||||
func (this *HTTPHeaderPolicyRef) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
7
pkg/serverconfigs/shared/http_header_ref.go
Normal file
7
pkg/serverconfigs/shared/http_header_ref.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package shared
|
||||
|
||||
// Header引用
|
||||
type HTTPHeaderRef struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
HeaderId int64 `yaml:"headerId" json:"headerId"`
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package shared
|
||||
|
||||
// HeaderList定义
|
||||
type HTTPHeaderPolicy struct {
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
Name string `yaml:"name" json:"name"` // 名称 TODO
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 TODO
|
||||
Description string `yaml:"description" json:"description"` // 描述 TODO
|
||||
|
||||
AddHeaders []*HTTPHeaderConfig `yaml:"addHeaders" json:"addHeaders"` // TODO
|
||||
AddTrailers []*HTTPHeaderConfig `yaml:"addTrailers" json:"addTrailers"` // TODO
|
||||
SetHeaders []*HTTPHeaderConfig `yaml:"setHeaders" json:"setHeaders"` // TODO
|
||||
ReplaceHeaders []*HTTPHeaderConfig `yaml:"replaceHeaders" json:"replaceHeaders"` // 替换Header内容 TODO
|
||||
DeletedHeaders []string `yaml:"deleteHeaders" json:"deleteHeaders"` // 删除的Header TODO
|
||||
|
||||
Expires *HTTPExpireHeaderConfig `yaml:"expires" json:"expires"` // TODO
|
||||
}
|
||||
|
||||
// 获取新对象
|
||||
func NewHTTPHeaderPolicy() *HTTPHeaderPolicy {
|
||||
return &HTTPHeaderPolicy{}
|
||||
}
|
||||
|
||||
// 校验
|
||||
func (this *HTTPHeaderPolicy) Init() error {
|
||||
for _, h := range this.AddHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.AddTrailers {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.SetHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.ReplaceHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断是否为空
|
||||
func (this *HTTPHeaderPolicy) IsEmpty() bool {
|
||||
return len(this.AddHeaders) == 0 && len(this.AddTrailers) == 0 && len(this.SetHeaders) == 0 && len(this.ReplaceHeaders) == 0 && this.Expires == nil
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHeaderList_FormatHeaders(t *testing.T) {
|
||||
list := NewHTTPHeaderPolicy()
|
||||
err := list.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
75
pkg/serverconfigs/shared/http_headers_policy.go
Normal file
75
pkg/serverconfigs/shared/http_headers_policy.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package shared
|
||||
|
||||
import "strings"
|
||||
|
||||
// HeaderList定义
|
||||
type HTTPHeaderPolicy struct {
|
||||
Id int64 `yaml:"id" json:"id"` // ID
|
||||
Name string `yaml:"name" json:"name"` // 名称 TODO
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 TODO
|
||||
Description string `yaml:"description" json:"description"` // 描述 TODO
|
||||
|
||||
AddHeaderRefs []*HTTPHeaderRef `yaml:"addHeaderRefs" json:"addHeaderRefs"`
|
||||
AddHeaders []*HTTPHeaderConfig `yaml:"addHeaders" json:"addHeaders"`
|
||||
AddTrailerRefs []*HTTPHeaderRef `yaml:"addTrailerRefs" json:"addTrailerRefs"`
|
||||
AddTrailers []*HTTPHeaderConfig `yaml:"addTrailers" json:"addTrailers"` // TODO
|
||||
SetHeaderRefs []*HTTPHeaderRef `yaml:"setHeaderRefs" json:"setHeaderRefs"`
|
||||
SetHeaders []*HTTPHeaderConfig `yaml:"setHeaders" json:"setHeaders"`
|
||||
ReplaceHeaderRefs []*HTTPHeaderRef `yaml:"replaceHeaderRefs" json:"replaceHeaderRefs"`
|
||||
ReplaceHeaders []*HTTPHeaderConfig `yaml:"replaceHeaders" json:"replaceHeaders"` // 替换Header内容 TODO
|
||||
DeleteHeaders []string `yaml:"deleteHeaders" json:"deleteHeaders"` // 删除的Header
|
||||
|
||||
Expires *HTTPExpireHeaderConfig `yaml:"expires" json:"expires"` // TODO
|
||||
|
||||
deleteHeaderMap map[string]bool // header => bool
|
||||
}
|
||||
|
||||
// 校验
|
||||
func (this *HTTPHeaderPolicy) Init() error {
|
||||
for _, h := range this.AddHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.AddTrailers {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.SetHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for _, h := range this.ReplaceHeaders {
|
||||
err := h.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// delete
|
||||
this.deleteHeaderMap = map[string]bool{}
|
||||
for _, header := range this.DeleteHeaders {
|
||||
this.deleteHeaderMap[strings.ToUpper(header)] = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 判断是否为空
|
||||
func (this *HTTPHeaderPolicy) IsEmpty() bool {
|
||||
return len(this.AddHeaders) == 0 && len(this.AddTrailers) == 0 && len(this.SetHeaders) == 0 && len(this.ReplaceHeaders) == 0 && this.Expires == nil
|
||||
}
|
||||
|
||||
// 判断删除列表中是否包含某个Header
|
||||
func (this *HTTPHeaderPolicy) ContainsDeletedHeader(header string) bool {
|
||||
_, ok := this.deleteHeaderMap[strings.ToUpper(header)]
|
||||
return ok
|
||||
}
|
||||
57
pkg/serverconfigs/shared/http_headers_policy_test.go
Normal file
57
pkg/serverconfigs/shared/http_headers_policy_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHTTPHeaderPolicy_FormatHeaders(t *testing.T) {
|
||||
policy := &HTTPHeaderPolicy{}
|
||||
err := policy.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHTTPHeaderPolicy_ShouldDeleteHeader(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
policy := &HTTPHeaderPolicy{}
|
||||
err := policy.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(policy.ContainsDeletedHeader("Origin"))
|
||||
}
|
||||
{
|
||||
policy := &HTTPHeaderPolicy{
|
||||
DeleteHeaders: []string{"Hello", "World"},
|
||||
}
|
||||
err := policy.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsFalse(policy.ContainsDeletedHeader("Origin"))
|
||||
}
|
||||
{
|
||||
policy := &HTTPHeaderPolicy{
|
||||
DeleteHeaders: []string{"origin"},
|
||||
}
|
||||
err := policy.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(policy.ContainsDeletedHeader("Origin"))
|
||||
}
|
||||
{
|
||||
policy := &HTTPHeaderPolicy{
|
||||
DeleteHeaders: []string{"Origin"},
|
||||
}
|
||||
err := policy.Init()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
a.IsTrue(policy.ContainsDeletedHeader("Origin"))
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,9 @@ import (
|
||||
)
|
||||
|
||||
// 重写条件定义
|
||||
type RequestCond struct {
|
||||
Id string `yaml:"id" json:"id"` // ID
|
||||
type HTTPRequestCond struct {
|
||||
Id string `yaml:"id" json:"id"` // ID
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
|
||||
// 要测试的字符串
|
||||
// 其中可以使用跟请求相关的参数,比如:
|
||||
@@ -41,15 +42,8 @@ type RequestCond struct {
|
||||
arrayValue []string
|
||||
}
|
||||
|
||||
// 取得新对象
|
||||
func NewRequestCond() *RequestCond {
|
||||
return &RequestCond{
|
||||
Id: stringutil.Rand(16),
|
||||
}
|
||||
}
|
||||
|
||||
// 校验配置
|
||||
func (this *RequestCond) Init() error {
|
||||
func (this *HTTPRequestCond) Init() error {
|
||||
this.isInt = RegexpDigitNumber.MatchString(this.Value)
|
||||
this.isFloat = RegexpFloatNumber.MatchString(this.Value)
|
||||
|
||||
@@ -144,7 +138,7 @@ func (this *RequestCond) Init() error {
|
||||
}
|
||||
|
||||
// 将此条件应用于请求,检查是否匹配
|
||||
func (this *RequestCond) Match(formatter func(source string) string) bool {
|
||||
func (this *HTTPRequestCond) Match(formatter func(source string) string) bool {
|
||||
paramValue := formatter(this.Param)
|
||||
switch this.Operator {
|
||||
case RequestCondOperatorRegexp:
|
||||
@@ -361,7 +355,7 @@ func (this *RequestCond) Match(formatter func(source string) string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (this *RequestCond) ipToInt64(ip net.IP) int64 {
|
||||
func (this *HTTPRequestCond) ipToInt64(ip net.IP) int64 {
|
||||
if len(ip) == 0 {
|
||||
return 0
|
||||
}
|
||||
38
pkg/serverconfigs/shared/http_request_cond_group.go
Normal file
38
pkg/serverconfigs/shared/http_request_cond_group.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package shared
|
||||
|
||||
// 请求条件分组
|
||||
type HTTPRequestCondGroup struct {
|
||||
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
|
||||
Connector string `yaml:"connector" json:"connector"` // 条件之间的关系
|
||||
Conds []*HTTPRequestCond `yaml:"conds" json:"conds"` // 条件列表
|
||||
IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配
|
||||
}
|
||||
|
||||
// 初始化
|
||||
func (this *HTTPRequestCondGroup) Init() error {
|
||||
if len(this.Conds) > 0 {
|
||||
for _, cond := range this.Conds {
|
||||
err := cond.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *HTTPRequestCondGroup) Match(formatter func(source string) string) bool {
|
||||
if !this.IsOn {
|
||||
return !this.IsReverse
|
||||
}
|
||||
for _, cond := range this.Conds {
|
||||
isMatched := cond.Match(formatter)
|
||||
if this.Connector == "or" && isMatched {
|
||||
return !this.IsReverse
|
||||
}
|
||||
if this.Connector == "and" && !isMatched {
|
||||
return this.IsReverse
|
||||
}
|
||||
}
|
||||
return !this.IsReverse
|
||||
}
|
||||
@@ -14,7 +14,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello",
|
||||
Operator: RequestCondOperatorRegexp,
|
||||
Value: "abc",
|
||||
@@ -26,7 +26,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello",
|
||||
Operator: RequestCondOperatorRegexp,
|
||||
Value: "/\\w+",
|
||||
@@ -38,7 +38,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/article/123.html",
|
||||
Operator: RequestCondOperatorRegexp,
|
||||
Value: `^/article/\d+\.html$`,
|
||||
@@ -50,7 +50,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello",
|
||||
Operator: RequestCondOperatorRegexp,
|
||||
Value: "[",
|
||||
@@ -62,7 +62,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello",
|
||||
Operator: RequestCondOperatorNotRegexp,
|
||||
Value: "abc",
|
||||
@@ -74,7 +74,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello",
|
||||
Operator: RequestCondOperatorNotRegexp,
|
||||
Value: "/\\w+",
|
||||
@@ -86,7 +86,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123.123",
|
||||
Operator: RequestCondOperatorEqInt,
|
||||
Value: "123",
|
||||
@@ -98,7 +98,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123",
|
||||
Operator: RequestCondOperatorEqInt,
|
||||
Value: "123",
|
||||
@@ -110,7 +110,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "abc",
|
||||
Operator: RequestCondOperatorEqInt,
|
||||
Value: "abc",
|
||||
@@ -122,7 +122,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123",
|
||||
Operator: RequestCondOperatorEqFloat,
|
||||
Value: "123",
|
||||
@@ -134,7 +134,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123.0",
|
||||
Operator: RequestCondOperatorEqFloat,
|
||||
Value: "123",
|
||||
@@ -146,7 +146,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123.123",
|
||||
Operator: RequestCondOperatorEqFloat,
|
||||
Value: "123.12",
|
||||
@@ -158,7 +158,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123",
|
||||
Operator: RequestCondOperatorGtFloat,
|
||||
Value: "1",
|
||||
@@ -170,7 +170,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "123",
|
||||
Operator: RequestCondOperatorGtFloat,
|
||||
Value: "125",
|
||||
@@ -182,7 +182,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorGteFloat,
|
||||
Value: "125",
|
||||
@@ -194,7 +194,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorLtFloat,
|
||||
Value: "127",
|
||||
@@ -206,7 +206,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorLteFloat,
|
||||
Value: "127",
|
||||
@@ -218,7 +218,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorEqString,
|
||||
Value: "125",
|
||||
@@ -230,7 +230,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorNeqString,
|
||||
Value: "125",
|
||||
@@ -242,7 +242,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "125",
|
||||
Operator: RequestCondOperatorNeqString,
|
||||
Value: "127",
|
||||
@@ -254,7 +254,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorHasPrefix,
|
||||
Value: "/hello",
|
||||
@@ -266,7 +266,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorHasPrefix,
|
||||
Value: "/hello2",
|
||||
@@ -278,7 +278,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorHasSuffix,
|
||||
Value: "world",
|
||||
@@ -290,7 +290,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorHasSuffix,
|
||||
Value: "world/",
|
||||
@@ -302,7 +302,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorContainsString,
|
||||
Value: "wo",
|
||||
@@ -314,7 +314,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorContainsString,
|
||||
Value: "wr",
|
||||
@@ -326,7 +326,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorNotContainsString,
|
||||
Value: "HELLO",
|
||||
@@ -338,7 +338,7 @@ func TestRequestCond_Compare1(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "/hello/world",
|
||||
Operator: RequestCondOperatorNotContainsString,
|
||||
Value: "hello",
|
||||
@@ -354,7 +354,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "hello",
|
||||
Operator: RequestCondOperatorEqIP,
|
||||
Value: "hello",
|
||||
@@ -366,7 +366,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorEqIP,
|
||||
Value: "hello",
|
||||
@@ -378,7 +378,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorEqIP,
|
||||
Value: "192.168.1.100",
|
||||
@@ -390,7 +390,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorGtIP,
|
||||
Value: "192.168.1.90",
|
||||
@@ -402,7 +402,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorGteIP,
|
||||
Value: "192.168.1.90",
|
||||
@@ -414,7 +414,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.80",
|
||||
Operator: RequestCondOperatorLtIP,
|
||||
Value: "192.168.1.90",
|
||||
@@ -426,7 +426,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.0.100",
|
||||
Operator: RequestCondOperatorLteIP,
|
||||
Value: "192.168.1.90",
|
||||
@@ -438,7 +438,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.0.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "192.168.0.90,",
|
||||
@@ -450,7 +450,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.0.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "192.168.0.90,192.168.1.100",
|
||||
@@ -462,7 +462,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.0.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: ",192.168.1.100",
|
||||
@@ -474,7 +474,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "192.168.0.90,192.168.1.99",
|
||||
@@ -486,7 +486,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "192.168.0.90/24",
|
||||
@@ -498,7 +498,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "192.168.0.90/18",
|
||||
@@ -510,7 +510,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPRange,
|
||||
Value: "a/18",
|
||||
@@ -522,7 +522,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPMod10,
|
||||
Value: "6",
|
||||
@@ -534,7 +534,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPMod100,
|
||||
Value: "76",
|
||||
@@ -546,7 +546,7 @@ func TestRequestCond_IP(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "192.168.1.100",
|
||||
Operator: RequestCondOperatorIPMod,
|
||||
Value: "10,6",
|
||||
@@ -585,7 +585,7 @@ func TestRequestCondIPCompare(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{}
|
||||
cond := HTTPRequestCond{}
|
||||
t.Log(cond.ipToInt64(net.ParseIP("192.168.1.100")))
|
||||
t.Log(cond.ipToInt64(net.ParseIP("192.168.1.99")))
|
||||
t.Log(cond.ipToInt64(net.ParseIP("0.0.0.0")))
|
||||
@@ -600,7 +600,7 @@ func TestRequestCond_In(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a",
|
||||
Operator: RequestCondOperatorIn,
|
||||
Value: `a`,
|
||||
@@ -612,7 +612,7 @@ func TestRequestCond_In(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a",
|
||||
Operator: RequestCondOperatorIn,
|
||||
Value: `["a", "b"]`,
|
||||
@@ -624,7 +624,7 @@ func TestRequestCond_In(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "c",
|
||||
Operator: RequestCondOperatorNotIn,
|
||||
Value: `["a", "b"]`,
|
||||
@@ -636,7 +636,7 @@ func TestRequestCond_In(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a",
|
||||
Operator: RequestCondOperatorNotIn,
|
||||
Value: `["a", "b"]`,
|
||||
@@ -652,7 +652,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a",
|
||||
Operator: RequestCondOperatorFileExt,
|
||||
Value: `["jpeg", "jpg", "png"]`,
|
||||
@@ -664,7 +664,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a.gif",
|
||||
Operator: RequestCondOperatorFileExt,
|
||||
Value: `["jpeg", "jpg", "png"]`,
|
||||
@@ -676,7 +676,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a.png",
|
||||
Operator: RequestCondOperatorFileExt,
|
||||
Value: `["jpeg", "jpg", "png"]`,
|
||||
@@ -688,7 +688,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a.png",
|
||||
Operator: RequestCondOperatorFileExist,
|
||||
}
|
||||
@@ -699,7 +699,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: Tea.Root + "/README.md",
|
||||
Operator: RequestCondOperatorFileExist,
|
||||
}
|
||||
@@ -710,7 +710,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: Tea.Root + "/README.md?v=1",
|
||||
Operator: RequestCondOperatorFileExist,
|
||||
}
|
||||
@@ -721,7 +721,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: Tea.Root,
|
||||
Operator: RequestCondOperatorFileExist,
|
||||
}
|
||||
@@ -732,7 +732,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: Tea.Root,
|
||||
Operator: RequestCondOperatorFileExist,
|
||||
}
|
||||
@@ -743,7 +743,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "a.png",
|
||||
Operator: RequestCondOperatorFileNotExist,
|
||||
}
|
||||
@@ -754,7 +754,7 @@ func TestRequestCond_File(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: Tea.Root + "/README.md",
|
||||
Operator: RequestCondOperatorFileNotExist,
|
||||
}
|
||||
@@ -769,7 +769,7 @@ func TestRequestCond_MimeType(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "text/html; charset=utf-8",
|
||||
Operator: RequestCondOperatorFileMimeType,
|
||||
Value: `["text/html"]`,
|
||||
@@ -781,7 +781,7 @@ func TestRequestCond_MimeType(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "text/html; charset=utf-8",
|
||||
Operator: RequestCondOperatorFileMimeType,
|
||||
Value: `["text/*"]`,
|
||||
@@ -793,7 +793,7 @@ func TestRequestCond_MimeType(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "text/html; charset=utf-8",
|
||||
Operator: RequestCondOperatorFileMimeType,
|
||||
Value: `["image/*"]`,
|
||||
@@ -805,7 +805,7 @@ func TestRequestCond_MimeType(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "text/plain; charset=utf-8",
|
||||
Operator: RequestCondOperatorFileMimeType,
|
||||
Value: `["text/html", "image/jpeg", "image/png"]`,
|
||||
@@ -821,7 +821,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1.0",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `1.0,1.1`,
|
||||
@@ -833,7 +833,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1.0",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `1.0,`,
|
||||
@@ -845,7 +845,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1.0",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `,1.1`,
|
||||
@@ -857,7 +857,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "0.9",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `1.0,1.1`,
|
||||
@@ -869,7 +869,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "0.9",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `1.0`,
|
||||
@@ -881,7 +881,7 @@ func TestRequestCond_Version(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1.1",
|
||||
Operator: RequestCondOperatorVersionRange,
|
||||
Value: `1.0`,
|
||||
@@ -903,7 +903,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
a := assert.NewAssertion(t)
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "1",
|
||||
@@ -915,7 +915,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "2",
|
||||
@@ -927,7 +927,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "3",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "3",
|
||||
@@ -939,7 +939,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "1",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "11,1",
|
||||
@@ -951,7 +951,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "3",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "11,3",
|
||||
@@ -963,7 +963,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
{
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: "4",
|
||||
Operator: RequestCondOperatorMod,
|
||||
Value: "2,0",
|
||||
@@ -975,7 +975,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: fmt.Sprintf("%d", i),
|
||||
Operator: RequestCondOperatorMod10,
|
||||
Value: fmt.Sprintf("%d", i%10),
|
||||
@@ -987,7 +987,7 @@ func TestRequestCond_Mod(t *testing.T) {
|
||||
}
|
||||
|
||||
for i := 0; i < 2000; i++ {
|
||||
cond := RequestCond{
|
||||
cond := HTTPRequestCond{
|
||||
Param: fmt.Sprintf("%d", i),
|
||||
Operator: RequestCondOperatorMod100,
|
||||
Value: fmt.Sprintf("%d", i%100),
|
||||
Reference in New Issue
Block a user