Skip to content

Commit

Permalink
removing pointless comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeker12 committed Jul 8, 2024
1 parent 45144d2 commit 2d37ff9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
5 changes: 2 additions & 3 deletions redirecthandler/redirecthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net/url"
"sync"

"github.com/deploymenttheory/go-api-http-client/status"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -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))
Expand All @@ -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())
}

Expand Down
82 changes: 41 additions & 41 deletions status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -76,23 +76,23 @@ 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]
}

// 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]
Expand Down

0 comments on commit 2d37ff9

Please sign in to comment.