From af1d6aa8e0df416c0b4bd464bba8d6a1993b5c25 Mon Sep 17 00:00:00 2001 From: Andrew Gerhold Date: Fri, 27 Nov 2020 15:19:52 -0800 Subject: [PATCH] Update handlers.go Added teapot as default response --- handlers/handlers.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/handlers/handlers.go b/handlers/handlers.go index 29a26d7e..5da8ffec 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -212,7 +212,7 @@ func returnJson(d interface{}, w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(d) } -func returnResponseCode(d interface{}, w http.ResponseWriter, r *http.Request) { +func returnResponseCode(s *Service, w http.ResponseWriter, r *http.Request) { if e, ok := d.(errors.Error); ok { w.WriteHeader(e.Status()) json.NewEncoder(w).Encode(e) @@ -224,13 +224,15 @@ func returnResponseCode(d interface{}, w http.ResponseWriter, r *http.Request) { return } - // https://golang.org/src/net/http/server.go?s=3003:5866#L150 // Go does not currently // support sending user-defined 1xx informational headers, // with the exception of 100-continue response header that the // Server sends automatically when the Request.Body is read. - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(d) + // https://golang.org/src/net/http/server.go?s=3003:5866#L150 + if LastStatusCode >= 100 { + w.WriteHeader(s.LastStatusCode) + } + return w.WriteHeader(http.StatusTeapot) } // error404Handler is a HTTP handler for 404 error pages