From 74d08126b3a95ba932e6997b4e18aac851b4e291 Mon Sep 17 00:00:00 2001 From: Lucas Roesler Date: Sun, 23 Jun 2019 20:46:34 +0200 Subject: [PATCH] Handle unexpected statuscodes from the log provider **What** - Use NotImplemented when we get a 404 from the log provider. When we get a 200, process the log request, as normal. For all other status codes, return a sever error with a message stating that the response was unexpected. The message will contain the original status code to assist with debugging Signed-off-by: Lucas Roesler --- gateway/handlers/logs.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/gateway/handlers/logs.go b/gateway/handlers/logs.go index 7b784efa..66ea6ba9 100644 --- a/gateway/handlers/logs.go +++ b/gateway/handlers/logs.go @@ -2,6 +2,7 @@ package handlers import ( "context" + "fmt" "io" "log" "net/http" @@ -66,17 +67,25 @@ func NewLogHandlerFunc(logProvider url.URL, timeout time.Duration) http.HandlerF } defer logResp.Body.Close() - // watch for connection closures and stream data - // connections and contexts should have cancel methods deferred already - select { - case err := <-copyNotify(&unbufferedWriter{wf}, logResp.Body): - if err != nil { - log.Printf("LogProxy: error while copy: %s", err.Error()) + switch logResp.StatusCode { + case http.StatusNotFound, http.StatusNotImplemented: + w.WriteHeader(http.StatusNotImplemented) + return + case http.StatusOK: + // watch for connection closures and stream data + // connections and contexts should have cancel methods deferred already + select { + case err := <-copyNotify(&unbufferedWriter{wf}, logResp.Body): + if err != nil { + log.Printf("LogProxy: error while copy: %s", err.Error()) + return + } + case <-cn.CloseNotify(): + log.Printf("LogProxy: client connection closed") return } - case <-cn.CloseNotify(): - log.Printf("LogProxy: client connection closed") - return + default: + http.Error(w, fmt.Sprintf("unknown log request error (%v)", logResp.StatusCode), http.StatusInternalServerError) } return