lib/simple_aws/s3.rb in simple_aws-1.2.0 vs lib/simple_aws/s3.rb in simple_aws-1.2.1
- old
+ new
@@ -127,10 +127,24 @@
def get(path, options = {})
call :get, path, options
end
##
+ # Send a request using HTTP POST
+ #
+ # @param path [String] The path of the resource at hand
+ # @param options [Hash] Options as defined above
+ #
+ # @return [SimpleAWS::Response] The results of the request
+ #
+ # @raise [SimpleAWS::UnsuccessfulResponse, SimpleAWS::UnknownErrorResponse] on response errors
+ ##
+ def post(path, options = {})
+ call :post, path, options
+ end
+
+ ##
# Send a request using HTTP PUT
#
# @param path [String] The path of the resource at hand
# @param options [Hash] Options as defined above
#
@@ -182,11 +196,11 @@
# @raise [SimpleAWS::UnsuccessfulResponse, SimpleAWS::UnknownErrorResponse] on response errors
##
def call(method, path, options = {})
request = self.build_request method, path, options
- connection = SimpleAWS::Connection.new
+ connection = SimpleAWS::Connection.new self
connection.call finish_and_sign_request(request)
end
##
# Build a request but do not send it. Helpful for debugging.
@@ -232,14 +246,19 @@
request.path = request.path + "?#{to_add}"
end
request.body = options[:body]
- if request.body.respond_to?(:read)
- request.headers["Content-Type"] ||= "application/octet-stream"
- request.headers["Content-Length"] = File.size(request.body).to_s
- request.headers["Expect"] = "100-continue"
+ if request.body
+ request.headers["Content-Length"] = calculate_size_of(request.body).to_s
+
+ if request.body.respond_to?(:read)
+ request.headers["Content-Type"] ||= "application/octet-stream"
+ request.headers["Expect"] = "100-continue"
+ end
+
+ request.headers["Content-Type"] ||= "application/x-www-form-urlencoded"
end
request
end
@@ -252,9 +271,13 @@
@uri += ".amazonaws.com"
@uri
end
protected
+
+ def calculate_size_of(body)
+ body.respond_to?(:size) ? body.size : File.size(body)
+ end
##
# Build and sign the final request, as per the rules here:
# http://docs.amazonwebservices.com/AmazonS3/latest/dev/RESTAuthentication.html
##