http hook should accept more than 200 statusCode (#13180)

Co-authored-by: Klaus Post <klauspost@gmail.com>
This commit is contained in:
ArthurMa 2021-09-11 05:27:37 +08:00 committed by GitHub
parent 39d51ce845
commit 2807c11410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,7 +98,7 @@ func (h *Target) Init() error {
// Drain any response. // Drain any response.
xhttp.DrainBody(resp.Body) xhttp.DrainBody(resp.Body)
if resp.StatusCode != http.StatusOK { if !acceptedResponseStatusCode(resp.StatusCode) {
switch resp.StatusCode { switch resp.StatusCode {
case http.StatusForbidden: case http.StatusForbidden:
return fmt.Errorf("%s returned '%s', please check if your auth token is correctly set", 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 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() { func (h *Target) startHTTPLogger() {
// Create a routine which sends json logs received // Create a routine which sends json logs received
// from an internal channel. // from an internal channel.