def gen_headers(opts)
      now = Time.now.httpdate
      sig = gen_signature('date: ' + now)

      headers = [[ 'Date',           now        ],
                 [ 'Authorization',  sig        ],
                 [ 'User-Agent',     HTTP_AGENT ],
                 [ 'Accept-Version', '~1.0'     ]]


       # headers for conditional requests (dates)
       for arg, conditional in [[:if_modified_since,   'If-Modified-Since'  ],
                                [:if_unmodified_since, 'If-Unmodified-Since']]
        date = opts[arg]
        next unless date

        date = Time.parse(date.to_s) unless date.kind_of? Time
        headers.push([conditional, date])
      end

      # headers for conditional requests (etags)
      for arg, conditional in [[:if_match,      'If-Match'     ],
                               [:if_none_match, 'If-None-Match']]
        etag = opts[arg]
        next unless etag

        raise ArgumentError unless etag.kind_of? String
        headers.push([conditional, etag])
      end

      origin = opts[:origin]
      if origin
        raise ArgumentError unless origin == 'null' || origin =~ CORS_ORIGIN_REGEX
        headers.push([ 'Origin',  origin ])
      end

      custom_headers = opts.keys.select { |key| key.to_s.start_with? 'm_' }
      unless custom_headers.empty?
        headers += custom_headers.map do |header_key|
          [ symbol_to_header(header_key), opts[header_key] ]
        end
      end

      # add md5 hash when sending data
      data = opts[:data]
      if data
        md5 = Digest::MD5.base64digest(data)
        headers.push([ 'Content-MD5', md5 ])
      end

      return headers
    end
def gen_headers(opts)
      now = Time.now.httpdate
      sig = gen_signature('date: ' + now)

      headers = [[ 'Date',           now        ],
                 [ 'Authorization',  sig        ],
                 [ 'User-Agent',     HTTP_AGENT ],
                 [ 'Accept-Version', '~1.0'     ]]


       # headers for conditional requests (dates)
       for arg, conditional in [[:if_modified_since,   'If-Modified-Since'  ],
                                [:if_unmodified_since, 'If-Unmodified-Since']]
        date = opts[arg]
        next unless date

        date = Time.parse(date.to_s) unless date.kind_of? Time
        headers.push([conditional, date])
      end

      # headers for conditional requests (etags)
      for arg, conditional in [[:if_match,      'If-Match'     ],
                               [:if_none_match, 'If-None-Match']]
        etag = opts[arg]
        next unless etag

        raise ArgumentError unless etag.kind_of? String
        headers.push([conditional, etag])
      end

      origin = opts[:origin]
      if origin
        raise ArgumentError unless origin == 'null' || origin =~ CORS_ORIGIN_REGEX
        headers.push([ 'Origin',  origin ])
      end

      custom_headers = opts.keys.select { |key| key.to_s.start_with? 'm_' }
      unless custom_headers.empty?
        headers += custom_headers.map do |header_key|
          [ symbol_to_header(header_key), opts[header_key] ]
        end
      end

      # add md5 hash when sending data
      data = opts[:data]
      if data
        md5 = Digest::MD5.base64digest(data)
        headers.push([ 'Content-MD5', md5 ])
      end

      return headers
    end
Creates headers to be given to the HTTP client and sent to the Manta
 service. The most important is the Authorization header, without which
 none of this class would work.