Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 9cf1364

Browse files
committed
added check around route matcher
1 parent 5af6a1f commit 9cf1364

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

proxy/proxy.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func handler(
9191
return func(w http.ResponseWriter, r *http.Request) {
9292
logger.Printf("inbound request on '%s %s'\n", r.Method, r.URL.String())
9393

94-
matchedRoute, err := matchRoute(conf, matcher, r)
94+
matchedRoute, err := matchRoute(conf, matcher, r, mocksEnabled)
9595
if err != nil {
9696
logger.Printf(err.Error())
9797
w.WriteHeader(http.StatusBadGateway)
@@ -121,19 +121,21 @@ func handler(
121121
}
122122
}
123123

124-
func matchRoute(conf domain.Config, matcher domain.Matcher, r *http.Request) (*domain.Route, error) {
124+
func matchRoute(conf domain.Config, matcher domain.Matcher, r *http.Request, mocksEnabled bool) (*domain.Route, error) {
125125
for _, route := range conf.Routes {
126126
switch route.Type {
127127
case domain.RouteTypeProxy:
128128
if route.PathPattern.MatchString(r.URL.Path) {
129129
return &route, nil
130130
}
131131
case domain.RouteTypeMock:
132-
if route.Mock == nil {
133-
return nil, errors.New("missing mock in config")
134-
}
135-
if matcher.Match(r, *route.Mock) {
136-
return &route, nil
132+
if mocksEnabled {
133+
if route.Mock == nil {
134+
return nil, errors.New("missing mock in config")
135+
}
136+
if matcher.Match(r, *route.Mock) {
137+
return &route, nil
138+
}
137139
}
138140
default:
139141
return nil, fmt.Errorf("unknown route type '%s'", route.Type)

0 commit comments

Comments
 (0)