cleanup and typo fixes

This commit is contained in:
Wesley Beary 2009-06-10 09:56:33 -07:00
parent a9b56db2e4
commit 87161229d9
2 changed files with 15 additions and 10 deletions

View File

@ -30,15 +30,17 @@ module Fog
def request
uri = URI.parse(@url)
path = "#{uri.path}#{uri.query.nil? ? "" : "?#{uri.query}"}"
host = "#{uri.host}#{uri.port == 80 ? "" : ":#{uri.port}"}"
path = "#{uri.path}"
path << "?#{uri.query}" if uri.query
host = "#{uri.host}"
host << ":#{uri.port}" unless uri.port == 80
@headers.merge!({'Host' => host})
request = "#{method} #{path} HTTP/1.1\r\n"
for key, value in headers
request << "#{key}: #{value}\r\n"
end
request << "\r\n#{@body}" if @body
request << "\r\n"
request << "#{@body}\r\n" if @body
send_data(request)
end

View File

@ -201,22 +201,25 @@ module Fog
def url(bucket_name = nil, path = nil)
url = "#{@scheme}://"
url << "#{bucket_name}." if bucket_name
url << "#{@host}:#{@port}/"
url << path if path
url << "#{@host}:#{@port}/#{path}"
url
end
def canonicalize_amz_headers(headers)
headers = headers.select {|key,value| key.match(/^x-amz-/iu)}.sort {|x,y| x[0] <=> y[0]}.collect {|header| header.join(':')}.join("\n").downcase
headers.empty? ? nil : headers
if headers.empty?
nil
else
headers.select {|key,value| key.match(/^x-amz-/iu)}.sort {|x,y| x[0] <=> y[0]}.collect {|header| header.join(':')}.join("\n").downcase
end
end
def canonicalize_resource(uri)
resource = "/#{'s3.amazonaws.com' == uri.host ? "" : "#{uri.host.split('.s3.amazonaws.com')[0]}/"}"
resource = "/"
resource << "#{match[1]}/" if match = uri.host.match(/(.*).s3.amazonaws.com/)
resource << "#{uri.path[1..-1]}" if uri.path
resource << "?location" if uri.to_s.include?('?acl')
resource << "?acl" if uri.to_s.include?('?acl')
resource << "?location" if uri.to_s.include?('?location')
resource << "?location" if uri.to_s.include?('?torrent')
resource << "?torrent" if uri.to_s.include?('?torrent')
resource
end