1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Temporary redirect should not execute the block

This commit is contained in:
Viven 2011-02-09 20:36:12 +08:00 committed by Wesley Beary
parent 7166d35d6b
commit 57b25e5645

View file

@ -337,20 +337,19 @@ DATA
signature = Base64.encode64(signed_string).chomp!
end
private
def request(params, &block)
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
params[:expects] = [307, *params[:expects]].flatten
# FIXME: ToHashParser should make this not needed
original_params = params.dup
response = @connection.request(params, &block)
if response.status == 307
uri = URI.parse(response.headers['Location'])
begin
response = @connection.request(params, &block)
rescue Excon::Errors::TemporaryRedirect => error
uri = URI.parse(error.response.headers['Location'])
Formatador.display_line("[yellow][WARN] fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant[/]")
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false).request(original_params, &block)
end