From 9cf13641844153e88f46d0b4f5347603fc400f83 Mon Sep 17 00:00:00 2001 From: Jacques Coney Date: Fri, 20 Sep 2019 12:05:48 +0100 Subject: [PATCH] added check around route matcher --- proxy/proxy.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index bbc424f..3f9ef7b 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -91,7 +91,7 @@ func handler( return func(w http.ResponseWriter, r *http.Request) { logger.Printf("inbound request on '%s %s'\n", r.Method, r.URL.String()) - matchedRoute, err := matchRoute(conf, matcher, r) + matchedRoute, err := matchRoute(conf, matcher, r, mocksEnabled) if err != nil { logger.Printf(err.Error()) w.WriteHeader(http.StatusBadGateway) @@ -121,7 +121,7 @@ func handler( } } -func matchRoute(conf domain.Config, matcher domain.Matcher, r *http.Request) (*domain.Route, error) { +func matchRoute(conf domain.Config, matcher domain.Matcher, r *http.Request, mocksEnabled bool) (*domain.Route, error) { for _, route := range conf.Routes { switch route.Type { case domain.RouteTypeProxy: @@ -129,11 +129,13 @@ func matchRoute(conf domain.Config, matcher domain.Matcher, r *http.Request) (*d return &route, nil } case domain.RouteTypeMock: - if route.Mock == nil { - return nil, errors.New("missing mock in config") - } - if matcher.Match(r, *route.Mock) { - return &route, nil + if mocksEnabled { + if route.Mock == nil { + return nil, errors.New("missing mock in config") + } + if matcher.Match(r, *route.Mock) { + return &route, nil + } } default: return nil, fmt.Errorf("unknown route type '%s'", route.Type)