mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-20 23:41:23 +02:00
fix(middleware): fix route bypass matching
- replace upstream headers approach with context value
This commit is contained in:
@@ -8,7 +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/gphttp/reverseproxy"
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
)
|
||||
@@ -242,7 +242,7 @@ var checkers = map[string]struct {
|
||||
builder: func(args any) CheckFunc {
|
||||
route := args.(string)
|
||||
return func(_ Cache, r *http.Request) bool {
|
||||
return r.Header.Get(httpheaders.HeaderUpstreamName) == route
|
||||
return reverseproxy.TryGetUpstreamName(r) == route
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/net/gphttp/httpheaders"
|
||||
"github.com/yusing/go-proxy/internal/net/gphttp/reverseproxy"
|
||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
@@ -305,11 +305,7 @@ func TestOnCorrectness(t *testing.T) {
|
||||
{
|
||||
name: "route_match",
|
||||
checker: "route example",
|
||||
input: &http.Request{
|
||||
Header: http.Header{
|
||||
httpheaders.HeaderUpstreamName: {"example"},
|
||||
},
|
||||
},
|
||||
input: reverseproxy.NewReverseProxy("example", nil, http.DefaultTransport).WithContextValue(&http.Request{}),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user