diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb
index fae9900f3..66ae1876c 100644
--- a/lib/fog/aws.rb
+++ b/lib/fog/aws.rb
@@ -23,8 +23,12 @@ module Fog
end
def request(params)
- unless params[:path] && params[:path][0] == '/'
- params[:path] = '/' << params[:path].to_s
+ params[:path] ||= ''
+ unless params[:path][0] == '/'
+ params[:path] = '/' + params[:path].to_s
+ end
+ if params[:query]
+ params[:path] << "?#{params[:query]}"
end
request = "#{params[:method]} #{params[:path]} HTTP/1.1\r\n"
params[:headers] ||= {}
@@ -48,15 +52,17 @@ module Fog
header = data.split(': ')
response.headers[header[0]] = header[1]
end
- if response.headers['Content-Length']
- response.body << @connection.read(response.headers['Content-Length'].to_i)
- elsif response.headers['Transfer-Encoding'] == 'chunked'
- while true
- # 2 == "/r/n".length
- chunk_size = @connection.readline.chomp!.to_i(16) + 2
- response.body << @connection.read(chunk_size)
- if chunk_size == 2
- break
+ unless params[:method] == 'HEAD'
+ if response.headers['Content-Length']
+ response.body << @connection.read(response.headers['Content-Length'].to_i)
+ elsif response.headers['Transfer-Encoding'] == 'chunked'
+ while true
+ # 2 == "/r/n".length
+ chunk_size = @connection.readline.chomp!.to_i(16) + 2
+ response.body << @connection.read(chunk_size)
+ if chunk_size == 2
+ break
+ end
end
end
end
diff --git a/lib/fog/aws/s3.rb b/lib/fog/aws/s3.rb
index d452ba508..0669754ff 100644
--- a/lib/fog/aws/s3.rb
+++ b/lib/fog/aws/s3.rb
@@ -42,6 +42,7 @@ module Fog
def get_service
request({
:headers => {},
+ :host => @host,
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetServiceParser.new,
:url => @host
@@ -56,11 +57,12 @@ module Fog
# :location_constraint sets the location for the bucket
def put_bucket(bucket_name, options = {})
if options[:location_constraint]
- data = <<-DATA
-
- #{options[:location_constraint]}
-
- DATA
+ data =
+<<-DATA
+
+ #{options[:location_constraint]}
+
+DATA
else
data = nil
end
@@ -79,17 +81,19 @@ module Fog
# bucket_name<~String>:: name of bucket to modify
# payer<~String>:: valid values are BucketOwner or Requester
def put_request_payment(bucket_name, payer)
- data = <<-DATA
-
- #{payer}
-
- DATA
+ data =
+<<-DATA
+
+ #{payer}
+
+DATA
request({
:body => data,
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'PUT',
- :parser => Fog::Parsers::AWS::S3::BasicParser.new
+ :parser => Fog::Parsers::AWS::S3::BasicParser.new,
+ :query => "requestPayment"
})
end
@@ -116,7 +120,7 @@ module Fog
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetBucketParser.new,
- :path => query
+ :query => query
})
end
@@ -127,18 +131,18 @@ module Fog
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
:parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
- :path => '?requestpayment'
+ :query => 'requestpayment'
})
end
# Get location constraint for an S3 bucket
- def get_location(bucket_name)
+ def get_bucket_location(bucket_name)
request({
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'GET',
- :parser => Fog::Parsers::AWS::S3::GetRequestPayment.new,
- :path => '?location'
+ :parser => Fog::Parsers::AWS::S3::GetBucketLocation.new,
+ :query => 'location'
})
end
@@ -195,7 +199,6 @@ module Fog
:headers => {},
:host => "#{bucket_name}.#{@host}",
:method => 'HEAD',
- :parser => Fog::Parsers::AWS::S3::BasicParser.new,
:path => object_name
})
end
@@ -213,13 +216,6 @@ module Fog
private
- def url(bucket_name = nil, path = nil)
- url = "#{@scheme}://"
- url << "#{bucket_name}." if bucket_name
- url << "#{@host}:#{@port}/#{path}"
- url
- end
-
def parse_file(file)
metadata = {
:body => nil,
@@ -239,7 +235,6 @@ module Fog
def sign(params)
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
- params[:path] ||= ''
string_to_sign =
<<-DATA
@@ -250,18 +245,16 @@ module Fog
DATA
amz_headers, canonical_amz_headers = {}, ''
- for key, value in amz_headers
+ for key, value in params[:headers]
if key[0..5] == 'x-amz-'
amz_headers[key] = value
end
end
amz_headers = amz_headers.sort {|x, y| x[0] <=> y[0]}
for pair in amz_headers
- canonical_amz_headers << "#{pair[0]}: #{pair[1]}\r\n"
- end
- unless canonical_amz_headers.empty?
- string_to_sign << "#{canonical_amz_headers}\n"
+ canonical_amz_headers << "#{pair[0]}:#{pair[1]}\n"
end
+ string_to_sign << "#{canonical_amz_headers}"
canonical_resource = "/"
# [0..-18] is anything prior to .s3.amazonaws.com
@@ -270,6 +263,9 @@ DATA
canonical_resource << "#{subdomain}/"
end
canonical_resource << "#{params[:path]}"
+ if params[:query] && !params[:query].empty?
+ canonical_resource << "?#{params[:query]}"
+ end
# canonical_resource << "?acl" if params[:path].include?('?acl')
# canonical_resource << "?location" if params[:path].include?('?location')
# canonical_resource << "?torrent" if params[:path].include?('?torrent')
@@ -289,7 +285,8 @@ DATA
:headers => params[:headers],
:host => params[:host],
:method => params[:method],
- :path => params[:path]
+ :path => params[:path],
+ :query => params[:query]
})
if params[:parser] && !response.body.empty?
diff --git a/lib/fog/aws/s3/parsers.rb b/lib/fog/aws/s3/parsers.rb
index 12588eb75..663525baa 100644
--- a/lib/fog/aws/s3/parsers.rb
+++ b/lib/fog/aws/s3/parsers.rb
@@ -104,7 +104,7 @@ module Fog
end
- class GetLocation < Fog::Parsers::AWS::S3::BasicParser
+ class GetBucketLocation < Fog::Parsers::AWS::S3::BasicParser
def end_element(name)
case name
diff --git a/lib/fog/aws/simpledb.rb b/lib/fog/aws/simpledb.rb
index d960e4ee5..a46abfb0f 100644
--- a/lib/fog/aws/simpledb.rb
+++ b/lib/fog/aws/simpledb.rb
@@ -303,7 +303,7 @@ module Fog
response = @connection.request({
:host => @host,
:method => method,
- :path => method == 'GET' ? "?#{query}" : ""
+ :query => query
})
if parser && !response.body.empty?
diff --git a/spec/aws/s3/copy_object_spec.rb b/spec/aws/s3/copy_object_spec.rb
index c1065725a..f40abd7b3 100644
--- a/spec/aws/s3/copy_object_spec.rb
+++ b/spec/aws/s3/copy_object_spec.rb
@@ -18,10 +18,12 @@ describe 'S3.copy_object' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.copy_object(
+ actual = s3.copy_object(
'fogcopyobjectsource', 'fog_copy_object_source',
'fogcopyobjectdestination', 'fog_copy_object_destination'
)
+ actual.status.should == 200
+ p actual
end
end
\ No newline at end of file
diff --git a/spec/aws/s3/delete_bucket_spec.rb b/spec/aws/s3/delete_bucket_spec.rb
index 98b8e7c13..3d216d413 100644
--- a/spec/aws/s3/delete_bucket_spec.rb
+++ b/spec/aws/s3/delete_bucket_spec.rb
@@ -12,7 +12,9 @@ describe 'S3.delete_bucket' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.delete_bucket('fogdeletebucket')
+ actual = s3.delete_bucket('fogdeletebucket')
+ actual.status.should == 204
+ p actual
end
it 'should not include fogdeletebucket in get_service after delete_bucket' do
diff --git a/spec/aws/s3/delete_object_spec.rb b/spec/aws/s3/delete_object_spec.rb
index 2fb5da9df..02dc8e63c 100644
--- a/spec/aws/s3/delete_object_spec.rb
+++ b/spec/aws/s3/delete_object_spec.rb
@@ -14,7 +14,9 @@ describe 'S3.delete_object' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.delete_object('fogdeleteobject', 'fog_delete_object')
+ actual = s3.delete_object('fogdeleteobject', 'fog_delete_object')
+ actual.status.should == 204
+ p actual
end
end
\ No newline at end of file
diff --git a/spec/aws/s3/get_bucket_location_spec.rb b/spec/aws/s3/get_bucket_location_spec.rb
new file mode 100644
index 000000000..9fed78c42
--- /dev/null
+++ b/spec/aws/s3/get_bucket_location_spec.rb
@@ -0,0 +1,25 @@
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe 'S3.get_location' do
+
+ before(:all) do
+ s3.put_bucket('foggetlocation')
+ end
+
+ after(:all) do
+ s3.delete_bucket('foggetlocation')
+ end
+
+ it 'should return proper attributes' do
+ p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
+ actual = s3.get_bucket('foggetbucket')
+ actual.status.should == 200
+ p actual
+ end
+
+ it 'should return proper attributes' do
+ p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
+ actual s3.get_location('foggetlocation')
+ end
+
+end
\ No newline at end of file
diff --git a/spec/aws/s3/get_bucket_spec.rb b/spec/aws/s3/get_bucket_spec.rb
index eaca3aefe..9cc6d21c8 100644
--- a/spec/aws/s3/get_bucket_spec.rb
+++ b/spec/aws/s3/get_bucket_spec.rb
@@ -12,7 +12,9 @@ describe 'S3.get_bucket' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.get_bucket('fogputbucket')
+ actual = s3.get_bucket('foggetbucket')
+ actual.status.should == 200
+ p actual
end
end
diff --git a/spec/aws/s3/get_location_spec.rb b/spec/aws/s3/get_location_spec.rb
deleted file mode 100644
index 614a3234e..000000000
--- a/spec/aws/s3/get_location_spec.rb
+++ /dev/null
@@ -1,10 +0,0 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
-
-describe 'S3.get_location' do
-
- it 'should return proper attributes' do
- p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.get_location('foggetlocation')
- end
-
-end
\ No newline at end of file
diff --git a/spec/aws/s3/get_object_spec.rb b/spec/aws/s3/get_object_spec.rb
index bc8ea5d35..2d8ac7c18 100644
--- a/spec/aws/s3/get_object_spec.rb
+++ b/spec/aws/s3/get_object_spec.rb
@@ -15,7 +15,9 @@ describe 'S3.get_object' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.get_object('foggetobject', 'fog_get_object')
+ actual = s3.get_object('foggetobject', 'fog_get_object')
+ actual.status.should == 200
+ p actual
end
end
\ No newline at end of file
diff --git a/spec/aws/s3/get_service_spec.rb b/spec/aws/s3/get_service_spec.rb
index dd67d2490..9db544ba8 100644
--- a/spec/aws/s3/get_service_spec.rb
+++ b/spec/aws/s3/get_service_spec.rb
@@ -12,7 +12,9 @@ describe 'S3.get_service' do
it 'should return proper_attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.get_service
+ actual = s3.get_service
+ actual.status.should == 200
+ p actual
end
it 'should include foggetservice in get_service' do
diff --git a/spec/aws/s3/head_object_spec.rb b/spec/aws/s3/head_object_spec.rb
index 929ecaebb..d8210a73b 100644
--- a/spec/aws/s3/head_object_spec.rb
+++ b/spec/aws/s3/head_object_spec.rb
@@ -15,7 +15,9 @@ describe 'S3.head_object' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.head_object('fogheadobject', 'fog_head_object')
+ actual = s3.head_object('fogheadobject', 'fog_head_object')
+ actual.status.should == 200
+ p actual
end
end
\ No newline at end of file
diff --git a/spec/aws/s3/put_bucket_spec.rb b/spec/aws/s3/put_bucket_spec.rb
index 0261f8937..abe369e90 100644
--- a/spec/aws/s3/put_bucket_spec.rb
+++ b/spec/aws/s3/put_bucket_spec.rb
@@ -12,7 +12,9 @@ describe 'S3.put_bucket' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
- p s3.put_bucket('fogputbucket')
+ actual = s3.put_bucket('fogputbucket')
+ actual.status.should == 200
+ p actual
end
it 'should include fogputbucket in get_service buckets after put_bucket' do
diff --git a/spec/aws/s3/put_object_spec.rb b/spec/aws/s3/put_object_spec.rb
index 73c5fe7ca..1858fdb10 100644
--- a/spec/aws/s3/put_object_spec.rb
+++ b/spec/aws/s3/put_object_spec.rb
@@ -14,7 +14,9 @@ describe 'S3.put_object' do
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
file = File.open(File.dirname(__FILE__) + '/../../lorem.txt', 'r')
- p s3.put_object('fogputobject', 'fog_put_object', file)
+ actual = s3.put_object('fogputobject', 'fog_put_object', file)
+ actual.status.should == 200
+ p actual
end
end
\ No newline at end of file
diff --git a/spec/aws/s3/put_request_payment_spec.rb b/spec/aws/s3/put_request_payment_spec.rb
index fe837b5ee..1ac4003bb 100644
--- a/spec/aws/s3/put_request_payment_spec.rb
+++ b/spec/aws/s3/put_request_payment_spec.rb
@@ -2,6 +2,14 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe 'S3.put_request_payment' do
+ before(:all) do
+ s3.put_bucket('fogputrequestpayment')
+ end
+
+ after(:all) do
+ s3.delete_bucket('fogputrequestpayment')
+ end
+
it 'should return proper attributes' do
p 'SHOULD CHECK FOR PROPER ATTRIBUTES'
p s3.put_request_payment('fogputrequestpayment', 'Requester')