From 385e05075b8f3075a168b4ef1c359567c0d91924 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Sun, 18 Jun 2017 12:13:40 -0300 Subject: [PATCH] Avoid dialing if the instance IP doesn't exit --- handlers/reverseproxy.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/handlers/reverseproxy.go b/handlers/reverseproxy.go index 98ad132..ed5a72e 100644 --- a/handlers/reverseproxy.go +++ b/handlers/reverseproxy.go @@ -60,6 +60,14 @@ func (p *tcpProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { logFunc = p.ErrorLog.Printf } + vars := mux.Vars(r) + instanceIP := vars["node"] + + if i := core.InstanceFindByIP(strings.Replace(instanceIP, "-", ".", -1)); i == nil { + w.WriteHeader(http.StatusServiceUnavailable) + return + } + outreq := new(http.Request) // shallow copying *outreq = *r