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

Merge pull request #2281 from burns/aws_storage_connection

[aws|storage] ensure connection uses correct scheme, host and port
This commit is contained in:
Wesley Beary 2013-10-17 12:15:23 -07:00
commit be6a5955f0

View file

@ -184,9 +184,9 @@ module Fog
if params[:scheme]
scheme = params[:scheme]
port = params[:port]
port = params[:port] || DEFAULT_SCHEME_PORT[scheme]
else
scheme = @scheme || DEFAULT_SCHEME
scheme = @scheme
port = @port
end
if DEFAULT_SCHEME_PORT[scheme] == port
@ -225,7 +225,7 @@ module Fog
:host => host,
:port => port,
:path => path,
:headers => headers,
:headers => headers
})
#
@ -418,12 +418,10 @@ module Fog
@port = options[:port] || DEFAULT_SCHEME_PORT[@scheme]
@path_style = options[:path_style] || false
end
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
end
def reload
@connection.reset
@connection.reset if @connection
end
def signature(params, expires)
@ -493,6 +491,20 @@ DATA
@hmac = Fog::HMAC.new('sha1', @aws_secret_access_key)
end
def connection(scheme, host, port)
uri = "#{scheme}://#{host}:#{port}"
if @persistent
unless uri == @connection_uri
@connection_uri = uri
reload
@connection = nil
end
else
@connection = nil
end
@connection ||= Fog::Connection.new(uri, @persistent, @connection_options)
end
def request(params, &block)
refresh_credentials_if_expired
@ -502,7 +514,9 @@ DATA
signature = signature(params, expires)
params = request_params(params)
params.delete(:port) unless params[:port]
scheme = params.delete(:scheme)
host = params.delete(:host)
port = params.delete(:port) || DEFAULT_SCHEME_PORT[scheme]
params[:headers]['Date'] = expires
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature}"
@ -510,12 +524,12 @@ DATA
original_params = params.dup
begin
response = @connection.request(params, &block)
response = connection(scheme, host, port).request(params, &block)
rescue Excon::Errors::TemporaryRedirect => error
headers = (error.response.is_a?(Hash) ? error.response[:headers] : error.response.headers)
uri = URI.parse(headers['Location'])
Fog::Logger.warning("fog: followed redirect to #{uri.host}, connecting to the matching region will be more performant")
response = Fog::Connection.new("#{@scheme}://#{uri.host}:#{@port}", false, @connection_options).request(original_params, &block)
response = Fog::Connection.new("#{uri.scheme}://#{uri.host}:#{uri.port}", false, @connection_options).request(original_params, &block)
end
response