class AWS::S3::Client

Client class for Amazon Simple Storage Service (S3).

Constants

API_VERSION
CACHEABLE_REQUESTS

@private

EMPTY_BODY_ERRORS

@private

XMLNS

Protected Class Methods

bucket_method(method_name, verb, *args, &block) click to toggle source
# File lib/aws/s3/client.rb, line 48
def self.bucket_method(method_name, verb, *args, &block)

  method_options = (args.pop if args.last.kind_of?(Hash)) || {}
  xml_grammar = (args.pop if args.last.respond_to?(:rules))
  verb = verb.to_s.upcase
  subresource = args.first

  add_client_request_method(method_name) do

    configure_request do |req, options|
        require_bucket_name!(options[:bucket_name])
      req.http_method = verb
      req.bucket = options[:bucket_name]
      req.add_param(subresource) if subresource

      if header_options = method_options[:header_options]
        header_options.each do |(option_name, header)|
          req.headers[header] = options[option_name] if
            options[option_name]
        end
      end

    end

    instance_eval(&block) if block

    if xml_grammar

      parser = Core::XML::Parser.new(xml_grammar.rules)
    
      process_response do |resp|
        resp.data = parser.parse(resp.http_response.body)
        super(resp)
      end
    
      simulate_response do |resp|
        resp.data = parser.simulate
        super(resp)
      end
    
    end

  end
end
object_method(method_name, verb, *args, &block) click to toggle source
# File lib/aws/s3/client.rb, line 93
def self.object_method(method_name, verb, *args, &block)
  bucket_method(method_name, verb, *args) do
    configure_request do |req, options|
      validate_key!(options[:key])
      super(req, options)
      req.key = options[:key]
    end

    instance_eval(&block) if block
  end
end

Protected Instance Methods

add_sse_to_response(response) click to toggle source
# File lib/aws/s3/client.rb, line 975
def add_sse_to_response response
  if sse = response.http_response.header('x-amz-server-side-encryption')
    sse = sse.downcase.to_sym
  end
  response.data[:server_side_encryption] = sse
end
extract_error_details(response) click to toggle source
# File lib/aws/s3/client.rb, line 932
def extract_error_details response
  if 
    (response.http_response.status >= 300 ||
      response.request_type == :complete_multipart_upload) and
    body = response.http_response.body and
    error = Core::XML::Parser.parse(body) and
    error[:code]
  then
    [error[:code], error[:message]]
  end
end
new_request() click to toggle source
# File lib/aws/s3/client.rb, line 971
def new_request
  S3::Request.new
end
populate_error(resp) click to toggle source

There are a few of s3 requests that can generate empty bodies and yet still be errors. These return empty bodies to comply with the HTTP spec. We have to detect these errors specially.

# File lib/aws/s3/client.rb, line 947
def populate_error resp
  code = resp.http_response.status
  if EMPTY_BODY_ERRORS.include?(code) and resp.http_response.body.nil?
    error_class = EMPTY_BODY_ERRORS[code]
    resp.error = error_class.new(resp.http_request, resp.http_response)
  else
    super
  end
end
set_request_data(request, options, block) click to toggle source
# File lib/aws/s3/client.rb, line 966
def set_request_data request, options, block
  request.body_stream = data_stream_from(options, &block)
  request.headers['Content-Length'] = content_length_from(options)
end
should_retry?(response) click to toggle source
# File lib/aws/s3/client.rb, line 957
def should_retry? response
  super or
    response.request_type == :complete_multipart_upload &&
    extract_error_details(response)
    # complete multipart upload can return an error inside a 
    # 200 level response -- this forces us to parse the
    # response for errors every time
end