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 <roesler.lucas@gmail.com>
This commit is contained in:
Lucas Roesler 2019-06-23 20:46:34 +02:00 committed by Alex Ellis
parent 02ccccbe60
commit 74d08126b3

View File

@ -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