lib/async/http/relative_location.rb in async-http-0.50.2 vs lib/async/http/relative_location.rb in async-http-0.50.3

- old
+ new

@@ -30,12 +30,13 @@ end # A client wrapper which transparently handles both relative and absolute redirects to a given maximum number of hops. class RelativeLocation < ::Protocol::HTTP::Middleware DEFAULT_METHOD = GET - - def initialize(app, maximum_hops = 4) + + # maximum_hops is the max number of redirects. Set to 0 to allow 1 request with no redirects. + def initialize(app, maximum_hops = 3) super(app) @maximum_hops = maximum_hops end @@ -46,14 +47,14 @@ hops = 0 # We need to cache the body as it might be submitted multiple times. request.finish - while hops < @maximum_hops + while hops <= @maximum_hops response = super(request) - hops += 1 - + if response.redirection? + hops += 1 response.finish location = response.headers['location'] uri = URI.parse(location)