Implement setResponseStatus.

Co-authored-by: Hector Hurtado <hector.hurtado@bbva.com>
This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-18 13:07:57 +02:00
parent e161e14fd6
commit bf791a36c6
2 changed files with 104 additions and 0 deletions
+21
View File
@@ -2,8 +2,10 @@ package data
import (
"io"
"io/ioutil"
"net/http"
"net/textproto"
"strconv"
"github.com/BBVA/kapow/internal/server/model"
"github.com/gorilla/mux"
@@ -123,3 +125,22 @@ func getRequestFileContent(w http.ResponseWriter, r *http.Request, h *model.Hand
w.WriteHeader(http.StatusNotFound)
}
}
// FIXME: Allow any HTTP status code. Now we are limited by WriteHeader
// capabilities
func getResponseStatus(w http.ResponseWriter, r *http.Request, h *model.Handler) {
sb, err := ioutil.ReadAll(r.Body)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
si, err := strconv.Atoi(string(sb))
if http.StatusText(si) == "" {
w.WriteHeader(http.StatusBadRequest)
} else if err == nil {
h.Writer.WriteHeader(int(si))
} else {
w.WriteHeader(http.StatusBadRequest)
}
}