缓存条件类型增加“URL通配符”

This commit is contained in:
刘祥超
2023-06-16 11:34:59 +08:00
parent e42b13f278
commit 70bc6e7d8e
3 changed files with 153 additions and 37 deletions

View File

@@ -3,7 +3,6 @@ package shared
import (
"bytes"
"fmt"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/assert"
"net"
"regexp"
@@ -85,6 +84,78 @@ func TestRequestCond_Compare1(t *testing.T) {
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello",
Operator: RequestCondOperatorWildcardMatch,
Value: "/*",
}
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello/world",
Operator: RequestCondOperatorWildcardMatch,
Value: "/*/world",
}
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello/world",
Operator: RequestCondOperatorWildcardMatch,
Value: "/H*/world",
}
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello",
Operator: RequestCondOperatorWildcardMatch,
Value: "/hello/*",
}
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(format string) string {
return format
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello/world",
Operator: RequestCondOperatorWildcardNotMatch,
Value: "/hello/*",
}
a.IsNil(cond.Init())
a.IsFalse(cond.Match(func(format string) string {
return format
}))
}
{
var cond = HTTPRequestCond{
Param: "/hello",
Operator: RequestCondOperatorWildcardNotMatch,
Value: "/hello/*",
}
a.IsNil(cond.Init())
a.IsTrue(cond.Match(func(format string) string {
return format
}))
}
{
cond := HTTPRequestCond{
Param: "123.123",
@@ -687,7 +758,7 @@ func TestRequestCond_File(t *testing.T) {
}))
}
{
/**{
cond := HTTPRequestCond{
Param: "a.png",
Operator: RequestCondOperatorFileExist,
@@ -762,7 +833,7 @@ func TestRequestCond_File(t *testing.T) {
a.IsFalse(cond.Match(func(source string) string {
return source
}))
}
}**/
}
func TestRequestCond_MimeType(t *testing.T) {