def request(method, options)
      host = options.fetch(:host, S3.host)
      path = options.fetch(:path)
      body = options.fetch(:body, nil)
      params = options.fetch(:params, {})
      headers = options.fetch(:headers, {})

      # Must be done before adding params
      # Encodes all characters except forward-slash (/) and explicitly legal URL characters
      path = Addressable::URI.escape(path)

      if params
        params = params.is_a?(String) ? params : self.class.parse_params(params)
        path << "?#{params}"
      end

      request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != "HEAD", path)

      headers = self.class.parse_headers(headers)
      headers.each do |key, value|
        request[key] = value
      end

      if body
        if body.respond_to?(:read)
          request.body_stream = body
        else
          request.body = body
        end
        request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
      end

      send_request(host, request)
    end
def request(method, options)
      host = options.fetch(:host, S3.host)
      path = options.fetch(:path)
      body = options.fetch(:body, nil)
      params = options.fetch(:params, {})
      headers = options.fetch(:headers, {})

      # Must be done before adding params
      # Encodes all characters except forward-slash (/) and explicitly legal URL characters
      path = Addressable::URI.escape(path)

      if params
        params = params.is_a?(String) ? params : self.class.parse_params(params)
        path << "?#{params}"
      end

      request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != "HEAD", path)

      headers = self.class.parse_headers(headers)
      headers.each do |key, value|
        request[key] = value
      end

      if body
        if body.respond_to?(:read)
          request.body_stream = body
        else
          request.body = body
        end
        request.content_length = body.respond_to?(:lstat) ? body.stat.size : body.size
      end

      send_request(host, request)
    end
Creates new connection object.

 ==== Options
 * <tt>:access_key_id</tt> - Access key id (REQUIRED)
 * <tt>:secret_access_key</tt> - Secret access key (REQUIRED)
 * <tt>:use_ssl</tt> - Use https or http protocol (false by
   default)
 * <tt>:debug</tt> - Display debug information on the STDOUT
   (false by default)
 * <tt>:timeout</tt> - Timeout to use by the Net::HTTP object
   (60 by default)
 * <tt>:proxy</tt> - Hash for Net::HTTP Proxy settings
   { :host => "proxy.mydomain.com", :port => "80, :user => "user_a", :password => "secret" }
 * <tt>:chunk_size</tt> - Size of a chunk when streaming
   (1048576 (1 MiB) by default)
 Makes request with given HTTP method, sets missing parameters,
 adds signature to request header and returns response object
 (Net::HTTPResponse)

 ==== Parameters
 * <tt>method</tt> - HTTP Method symbol, can be <tt>:get</tt>,
   <tt>:put</tt>, <tt>:delete</tt>

 ==== Options:
 * <tt>:host</tt> - Hostname to connecto to, defaults
   to <tt>s3.amazonaws.com</tt>
 * <tt>:path</tt> - path to send request to (REQUIRED)
 * <tt>:body</tt> - Request body, only meaningful for
   <tt>:put</tt> request
 * <tt>:params</tt> - Parameters to add to query string for
   request, can be String or Hash
 * <tt>:headers</tt> - Hash of headers fields to add to request
   header

 ==== Returns
 Net::HTTPResponse object -- response from the server