diff --git a/lib/rack/client/follow_redirects.rb b/lib/rack/client/follow_redirects.rb index 7b3a4f4..d12d5b9 100644 --- a/lib/rack/client/follow_redirects.rb +++ b/lib/rack/client/follow_redirects.rb @@ -1,27 +1,27 @@ class Rack::Client::FollowRedirects - include Rack::Test::Methods + include Rack::Test::Methods - def initialize(app) - @app = app - end + def initialize(app) + @app = app + end - def call(env) - status, headers, body = @app.call(env) - response = Rack::Response.new(body, status, headers) - if response.redirect? - uri = URI.parse(response["Location"]) - new_env = {} - env.each do |k,v| - if %w| HTTP_HOST SERVER_NAME SERVER_PORT |.include?(k) - new_env[k] = v - end + def call(env) + status, headers, body = @app.call(env) + response = Rack::Response.new(body, status, headers) + if response.redirect? + uri = URI.parse(response["Location"]) + new_env = {} + env.each do |k,v| + if %w| HTTP_HOST SERVER_NAME SERVER_PORT |.include?(k) + new_env[k] = v end - new_env["REQUEST_METHOD"] = "GET" - session = Rack::Test::Session.new(@app) - env = session.send(:env_for, uri.to_s, new_env) - call(env) - else - [status, headers, body] end + new_env["REQUEST_METHOD"] = "GET" + session = Rack::Test::Session.new(@app) + env = session.send(:env_for, uri.to_s, new_env) + call(env) + else + [status, headers, body] end end +end