From 2d37ff9a1189349b180957029cf8793913320249 Mon Sep 17 00:00:00 2001 From: Joseph Little Date: Mon, 8 Jul 2024 15:26:04 +0100 Subject: [PATCH] removing pointless comments --- redirecthandler/redirecthandler.go | 5 +- status/status.go | 82 +++++++++++++++--------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/redirecthandler/redirecthandler.go b/redirecthandler/redirecthandler.go index 948f472..61e4310 100644 --- a/redirecthandler/redirecthandler.go +++ b/redirecthandler/redirecthandler.go @@ -6,7 +6,6 @@ import ( "net/url" "sync" - "github.com/deploymenttheory/go-api-http-client/status" "go.uber.org/zap" ) @@ -86,7 +85,7 @@ func (r *RedirectHandler) checkRedirect(req *http.Request, via []*http.Request) } lastResponse := via[len(via)-1].Response - if status.IsRedirectStatusCode(lastResponse.StatusCode) { + if lastResponse.StatusCode == http.StatusPermanentRedirect || lastResponse.StatusCode == http.StatusTemporaryRedirect { location, err := lastResponse.Location() if err != nil { r.Logger.Error("Failed to get location from redirect response", zap.Error(err)) @@ -105,7 +104,7 @@ func (r *RedirectHandler) checkRedirect(req *http.Request, via []*http.Request) } // Cache permanent redirects - if status.IsPermanentRedirect(lastResponse.StatusCode) { + if lastResponse.StatusCode == http.StatusPermanentRedirect { r.cachePermanentRedirect(req.URL.String(), newReqURL.String()) } diff --git a/status/status.go b/status/status.go index 79c0846..02fbb9d 100644 --- a/status/status.go +++ b/status/status.go @@ -18,11 +18,11 @@ import ( // The function returns true if the statusCode is one of the above redirect statuses, indicating that the client should follow the redirection as specified in the Location header of the response. func IsRedirectStatusCode(statusCode int) bool { switch statusCode { - case http.StatusMovedPermanently, // 301 - http.StatusFound, // 302 - http.StatusSeeOther, // 303 - http.StatusTemporaryRedirect, // 307 - http.StatusPermanentRedirect: // 308 + case http.StatusMovedPermanently, + http.StatusFound, + http.StatusSeeOther, + http.StatusTemporaryRedirect, + http.StatusPermanentRedirect: return true default: return false @@ -32,8 +32,8 @@ func IsRedirectStatusCode(statusCode int) bool { // IsPermanentRedirect checks if the provided HTTP status code is one of the permanent redirect codes. func IsPermanentRedirect(statusCode int) bool { switch statusCode { - case http.StatusMovedPermanently, // 301 - http.StatusPermanentRedirect: // 308 + case http.StatusMovedPermanently, + http.StatusPermanentRedirect: return true default: return false @@ -43,30 +43,30 @@ func IsPermanentRedirect(statusCode int) bool { // IsNonRetryableStatusCode checks if the provided response indicates a non-retryable error. func IsNonRetryableStatusCode(resp *http.Response) bool { nonRetryableStatusCodes := map[int]bool{ - http.StatusBadRequest: true, // 400 - Bad Request - http.StatusUnauthorized: true, // 401 - Unauthorized - http.StatusPaymentRequired: true, // 402 - Payment Required - http.StatusForbidden: true, // 403 - Forbidden - http.StatusNotFound: true, // 404 - Not Found - http.StatusMethodNotAllowed: true, // 405 - Method Not Allowed - http.StatusNotAcceptable: true, // 406 - Not Acceptable - http.StatusProxyAuthRequired: true, // 407 - Proxy Authentication Required - http.StatusConflict: true, // 409 - Conflict - http.StatusGone: true, // 410 - Gone - http.StatusLengthRequired: true, // 411 - Length Required - http.StatusPreconditionFailed: true, // 412 - Precondition Failed - http.StatusRequestEntityTooLarge: true, // 413 - Request Entity Too Large - http.StatusRequestURITooLong: true, // 414 - Request-URI Too Long - http.StatusUnsupportedMediaType: true, // 415 - Unsupported Media Type - http.StatusRequestedRangeNotSatisfiable: true, // 416 - Requested Range Not Satisfiable - http.StatusExpectationFailed: true, // 417 - Expectation Failed - http.StatusUnprocessableEntity: true, // 422 - Unprocessable Entity - http.StatusLocked: true, // 423 - Locked - http.StatusFailedDependency: true, // 424 - Failed Dependency - http.StatusUpgradeRequired: true, // 426 - Upgrade Required - http.StatusPreconditionRequired: true, // 428 - Precondition Required - http.StatusRequestHeaderFieldsTooLarge: true, // 431 - Request Header Fields Too Large - http.StatusUnavailableForLegalReasons: true, // 451 - Unavailable For Legal Reasons + http.StatusBadRequest: true, + http.StatusUnauthorized: true, + http.StatusPaymentRequired: true, + http.StatusForbidden: true, + http.StatusNotFound: true, + http.StatusMethodNotAllowed: true, + http.StatusNotAcceptable: true, + http.StatusProxyAuthRequired: true, + http.StatusConflict: true, + http.StatusGone: true, + http.StatusLengthRequired: true, + http.StatusPreconditionFailed: true, + http.StatusRequestEntityTooLarge: true, + http.StatusRequestURITooLong: true, + http.StatusUnsupportedMediaType: true, + http.StatusRequestedRangeNotSatisfiable: true, + http.StatusExpectationFailed: true, + http.StatusUnprocessableEntity: true, + http.StatusLocked: true, + http.StatusFailedDependency: true, + http.StatusUpgradeRequired: true, + http.StatusPreconditionRequired: true, + http.StatusRequestHeaderFieldsTooLarge: true, + http.StatusUnavailableForLegalReasons: true, } _, isNonRetryable := nonRetryableStatusCodes[resp.StatusCode] @@ -76,10 +76,10 @@ func IsNonRetryableStatusCode(resp *http.Response) bool { // IsTransientError checks if an error or HTTP response indicates a transient error. func IsTransientError(resp *http.Response) bool { transientStatusCodes := map[int]bool{ - http.StatusInternalServerError: true, // 500 Internal Server Error - http.StatusBadGateway: true, // 502 Bad Gateway - http.StatusServiceUnavailable: true, // 503 Service Unavailable - http.StatusGatewayTimeout: true, // 504 - Gateway Timeout + http.StatusInternalServerError: true, + http.StatusBadGateway: true, + http.StatusServiceUnavailable: true, + http.StatusGatewayTimeout: true, } return resp != nil && transientStatusCodes[resp.StatusCode] } @@ -87,12 +87,12 @@ func IsTransientError(resp *http.Response) bool { // IsRetryableStatusCode checks if the provided HTTP status code is considered retryable. func IsRetryableStatusCode(statusCode int) bool { retryableStatusCodes := map[int]bool{ - http.StatusRequestTimeout: true, // 408 - Request Timeout - http.StatusTooManyRequests: true, // 429 - http.StatusInternalServerError: true, // 500 - http.StatusBadGateway: true, // 502 - http.StatusServiceUnavailable: true, // 503 - http.StatusGatewayTimeout: true, // 504 + http.StatusRequestTimeout: true, + http.StatusTooManyRequests: true, + http.StatusInternalServerError: true, + http.StatusBadGateway: true, + http.StatusServiceUnavailable: true, + http.StatusGatewayTimeout: true, } _, retryable := retryableStatusCodes[statusCode]