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

[s3] cleanup, use persistent connection

This commit is contained in:
geemus 2010-05-23 19:55:12 -07:00
parent 4edf4c8f3c
commit b52c4a5c4b

View file

@ -64,7 +64,7 @@ module Fog
unless (mime_types = MIME::Types.of(filename)).empty? unless (mime_types = MIME::Types.of(filename)).empty?
metadata[:headers]['Content-Type'] = mime_types.first.content_type metadata[:headers]['Content-Type'] = mime_types.first.content_type
end end
metadata[:body] = data.read metadata[:body] = data
metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s metadata[:headers]['Content-Length'] = ::File.size(data.path).to_s
end end
# metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip # metadata[:headers]['Content-MD5'] = Base64.encode64(Digest::MD5.digest(metadata[:body])).strip
@ -151,12 +151,16 @@ module Fog
end end
@port = options[:port] || 443 @port = options[:port] || 443
@scheme = options[:scheme] || 'https' @scheme = options[:scheme] || 'https'
reset
end
def reset
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
end end
private private
def request(params, &block) def request(params, &block)
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}")
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000") 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)}" params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
@ -181,8 +185,8 @@ DATA
end end
end end
amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]} amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
for pair in amz_headers for key, value in amz_headers
canonical_amz_headers << "#{pair[0]}:#{pair[1]}\n" canonical_amz_headers << "#{key}:#{value}\n"
end end
string_to_sign << "#{canonical_amz_headers}" string_to_sign << "#{canonical_amz_headers}"