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

Merge pull request #2 from fog/v4_region_follower_fix

another attempt at s3 region redirecting
This commit is contained in:
Wesley Beary 2015-01-12 10:36:20 -06:00
commit 5c8865e954

View file

@ -550,12 +550,15 @@ module Fog
new_params[:host] = URI.parse(headers['Location']).host new_params[:host] = URI.parse(headers['Location']).host
else else
body = error.response.is_a?(Hash) ? error.response[:body] : error.response.body body = error.response.is_a?(Hash) ? error.response[:body] : error.response.body
# some errors provide info indirectly
new_params[:bucket_name] = %r{<Bucket>([^<]*)</Bucket>}.match(body).captures.first new_params[:bucket_name] = %r{<Bucket>([^<]*)</Bucket>}.match(body).captures.first
new_params[:host] = %r{<Endpoint>([^<]*)</Endpoint>}.match(body).captures.first new_params[:host] = %r{<Endpoint>([^<]*)</Endpoint>}.match(body).captures.first
# some errors provide it directly
@new_region = %r{<Region>([^<]*)</Region>}.match(body).captures.first
end end
Fog::Logger.warning("fog: followed redirect to #{host}, connecting to the matching region will be more performant") Fog::Logger.warning("fog: followed redirect to #{host}, connecting to the matching region will be more performant")
original_region, original_signer = @region, @signer original_region, original_signer = @region, @signer
@region = case new_params[:host] @region = @new_region || case new_params[:host]
when 's3.amazonaws.com', 's3-external-1.amazonaws.com' when 's3.amazonaws.com', 's3-external-1.amazonaws.com'
DEFAULT_REGION DEFAULT_REGION
else else