From 2807c1141019aa0e6a87f6dbf41ca7b15cfec71e Mon Sep 17 00:00:00 2001 From: ArthurMa <4406arthur@gmail.com> Date: Sat, 11 Sep 2021 05:27:37 +0800 Subject: [PATCH] http hook should accept more than 200 statusCode (#13180) Co-authored-by: Klaus Post --- internal/logger/target/http/http.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/logger/target/http/http.go b/internal/logger/target/http/http.go index 6084ae025..b8bb28b9c 100644 --- a/internal/logger/target/http/http.go +++ b/internal/logger/target/http/http.go @@ -98,7 +98,7 @@ func (h *Target) Init() error { // Drain any response. xhttp.DrainBody(resp.Body) - if resp.StatusCode != http.StatusOK { + if !acceptedResponseStatusCode(resp.StatusCode) { switch resp.StatusCode { case http.StatusForbidden: return fmt.Errorf("%s returned '%s', please check if your auth token is correctly set", @@ -112,6 +112,13 @@ func (h *Target) Init() error { return nil } +// Accepted HTTP Status Codes +var acceptedStatusCodeMap = map[int]bool{http.StatusOK: true, http.StatusCreated: true, http.StatusAccepted: true, http.StatusNoContent: true} + +func acceptedResponseStatusCode(code int) bool { + return acceptedStatusCodeMap[code] +} + func (h *Target) startHTTPLogger() { // Create a routine which sends json logs received // from an internal channel.