lib/s3/right_s3_interface.rb
#-----------------------------------------------------------------
#      Requests
#-----------------------------------------------------------------
# Produces canonical string for signing.
Requests
Produces canonical string for signing.
Requests Produces canonical string for signing .
def canonical_string(method, path, headers={}, expires=nil) 
      s3_headers = {}
      headers.each do |key, value|
        key = key.downcase
        value = case
                when value.is_a?(Array) then value.join('')
                else                         value.to_s
                end
        s3_headers[key] = value.strip if key[/^#{AMAZON_HEADER_PREFIX}|^content-md5$|^content-type$|^date$/o]
      end
      s3_headers['content-type'] ||= ''
      s3_headers['content-md5']  ||= ''
      s3_headers['date']           = ''      if s3_headers.has_key? 'x-amz-date'
      s3_headers['date']           = expires if expires
      out_string = "#{method}\n"
      s3_headers.sort { |a, b| a[0] <=> b[0] }.each do |key, value|
        out_string << (key[/^#{AMAZON_HEADER_PREFIX}/o] ? "#{key}:#{value}\n" : "#{value}\n")
      end
      out_string << path.gsub(/\?.*$/, '')
      S3_REQUEST_PARAMETERS.each do |parameter|
        if path[/[&?]#{parameter}(=[^&]*)?($|&)/]
          if $1
            value = CGI::unescape($1)
          else
            value = ''
          end
          out_string << (out_string[/[?]/] ? "&#{parameter}#{value}" : "?#{parameter}#{value}")
        end
      end
      out_string
    end
def canonical_string ( method , path , headers = { } , expires = nil ) s3_headers = { } headers . each do | key , value | key = key . downcase value = case when value . is_a? ( Array ) then value . join ( '' ) else value . to_s end s3_headers [ key ] = value . strip if key [ / ^ #{ AMAZON_HEADER_PREFIX } |^content-md5$|^content-type$|^date$ /o ] end s3_headers [ 'content-type' ] ||= '' s3_headers [ 'content-md5' ] ||= '' s3_headers [ 'date' ] = '' if s3_headers . has_key? 'x-amz-date' s3_headers [ 'date' ] = expires if expires out_string = "#{method}\n" s3_headers . sort { | a , b | a [ 0 ] <=> b [ 0 ] } . each do | key , value | out_string << ( key [ / ^ #{ AMAZON_HEADER_PREFIX } /o ] ? "#{key}:#{value}\n" : "#{value}\n" ) end out_string << path . gsub ( / \? .*$ / , '' ) S3_REQUEST_PARAMETERS . each do | parameter | if path [ / [&?] #{ parameter } (=[^&]*)?($|&) / ] if $1 value = CGI :: unescape ( $1 ) else value = '' end out_string << ( out_string [ / [?] / ] ? "&#{parameter}#{value}" : "?#{parameter}#{value}" ) end end out_string end
Requests
Produces canonical string for signing.
Requests Produces canonical string for signing .
# :nodoc: # prepare output string # ignore everything after the question mark by default... # ... unless there is a parameter that we care about.
method
<not_specific>
path
<not_specific>
headers
<not_specific>
expires
<not_specific>