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

This works for Amazon's 307s

This commit is contained in:
Lars Pind 2010-09-28 05:27:07 +08:00 committed by Wesley Beary
parent 68bca84e4f
commit f0cf5eecdf

View file

@ -165,13 +165,17 @@ module Fog
def request(params, &block)
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
org_params = params.dup
params[:expects] = [params[:expects] || [], 307].flatten
response = @connection.request(params, &block)
if response.status == 307
params[:host] = response['Error']['Endpoint']
response = @connection.request(params, &block)
if response.status == 307 && endpoint = response.body.match(/<Endpoint>([^<]+)<\/Endpoint>/)[1]
params = org_params
params[:host] = endpoint
# params[:expects] will now be reset to what it was before
# Redo the request, but to the specified endpoint
response = Fog::Connection.new("https://#{endpoint}:443", false).request(params, &block)
end
response