def parse_header(header)
      # decompose
      params = header[6,header.length].split(/[,=&]/)

      # odd number of arguments - must be a malformed header.
      raise OAuth::Problem.new("Invalid authorization header") if params.size % 2 != 0

      params.map! do |v|
        # strip and unescape
        val = unescape(v.strip)
        # strip quotes
        val.sub(/^\"(.*)\"$/, '\1')
      end

      # convert into a Hash
      Hash[*params.flatten]
    end
def parse_header(header)
      # decompose
      params = header[6,header.length].split(/[,=&]/)

      # odd number of arguments - must be a malformed header.
      raise OAuth::Problem.new("Invalid authorization header") if params.size % 2 != 0

      params.map! do |v|
        # strip and unescape
        val = unescape(v.strip)
        # strip quotes
        val.sub(/^\"(.*)\"$/, '\1')
      end

      # convert into a Hash
      Hash[*params.flatten]
    end
Parse an Authorization / WWW-Authenticate header into a hash. Takes care of unescaping and
 removing surrounding quotes. Raises a OAuth::Problem if the header is not parsable into a
 valid hash. Does not validate the keys or values.

   hash = parse_header(headers['Authorization'] || headers['WWW-Authenticate'])
   hash['oauth_timestamp']
     #=>"1234567890"