module Aws::Rest::Response::HeaderListParser

@api private

Public Class Methods

parse_string_list(value) click to toggle source

parse a list of possibly quoted and escaped string values Follows: # [RFC-7230’s specification of header values](datatracker.ietf.org/doc/html/rfc7230#section-3.2.6).

# File lib/aws-sdk-core/rest/response/header_list_parser.rb, line 15
def parse_string_list(value)
  buffer = StringScanner.new(value)
  parsed = []

  parsed << read_value(buffer) until buffer.eos?

  parsed
end
parse_timestamp_list(value, ref) click to toggle source
# File lib/aws-sdk-core/rest/response/header_list_parser.rb, line 24
def parse_timestamp_list(value, ref)
  # timestamp lists use an http-date by default and are unescaped
  # eg: Mon, 16 Dec 2019 23:48:18 GMT, Mon, 16 Dec 2019 23:48:18 GMT
  case ref['timestampFormat'] || ref.shape['timestampFormat']
  when 'unixTimestamp'
    value.split(', ').map { |v| Time.at(v.to_f) }
  when 'iso8601' then value.split(', ').map { |v| Time.parse(v) }
  else
    # header default to rfc822/http-date, which has a comma after day
    value.split(',').each_slice(2).map { |v| Time.parse(v[0] + v[1])}
  end
end

Private Class Methods

read_quoted_value(buffer) click to toggle source
# File lib/aws-sdk-core/rest/response/header_list_parser.rb, line 64
def read_quoted_value(buffer)
  # scan until we have an unescaped double quote
  value = buffer.scan_until(/[^\\]"/)
  raise ArgumentError, 'Invalid String list: No closing quote found' unless value

  # drop any remaining whitespace/commas
  buffer.scan_until(/[\s,]*/)
  # the last character will always be the closing quote.
  # Add a starting quote  and then unescape (undump)
  "\"#{value}".undump
end
read_unquoted_value(buffer) click to toggle source
# File lib/aws-sdk-core/rest/response/header_list_parser.rb, line 57
def read_unquoted_value(buffer)
  # there cannot be any escaped values
  value = buffer.scan_until(/,|$/)
  # drop the comma if we matched it
  buffer.matched == ',' ? value.chop : value
end
read_value(buffer) click to toggle source
# File lib/aws-sdk-core/rest/response/header_list_parser.rb, line 39
def read_value(buffer)
  until buffer.eos?
    case buffer.peek(1)
    when ' ', "\t"
      # drop leading whitespace
      buffer.getch
      next
    when '"'
      buffer.getch # drop the quote and advance
      return read_quoted_value(buffer)
    else
      return read_unquoted_value(buffer)
    end
  end
  # buffer is only whitespace
  nil
end