From 87161229d91cbc452195b1fa09e64ca96c2de4a3 Mon Sep 17 00:00:00 2001 From: Wesley Beary Date: Wed, 10 Jun 2009 09:56:33 -0700 Subject: [PATCH] cleanup and typo fixes --- lib/fog/aws.rb | 8 +++++--- lib/fog/aws/s3.rb | 17 ++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index d168e01e9..9a9e86836 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -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 diff --git a/lib/fog/aws/s3.rb b/lib/fog/aws/s3.rb index 571cd4f05..0acee6333 100644 --- a/lib/fog/aws/s3.rb +++ b/lib/fog/aws/s3.rb @@ -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