feat(rules.on): support route directive

This commit is contained in:
yusing
2025-05-05 19:34:24 +08:00
parent bf32cafd90
commit 62d3d200e6
3 changed files with 59 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/gobwas/glob"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
"github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
@@ -31,6 +32,7 @@ const (
OnPath = "path"
OnRemote = "remote"
OnBasicAuth = "basic_auth"
OnRoute = "route"
)
var checkers = map[string]struct {
@@ -229,6 +231,21 @@ var checkers = map[string]struct {
}
},
},
OnRoute: {
help: Help{
command: OnRoute,
args: map[string]string{
"route": "the route name",
},
},
validate: validateSingleArg,
builder: func(args any) CheckFunc {
route := args.(string)
return func(_ Cache, r *http.Request) bool {
return r.Header.Get(httpheaders.HeaderUpstreamName) == route
}
},
},
}
var asciiSpace = [256]uint8{'\t': 1, '\n': 1, '\v': 1, '\f': 1, '\r': 1, ' ': 1}