Module: Aws::Xray::HeaderParser

Extended by:
HeaderParser
Included in:
HeaderParser
Defined in:
lib/aws/xray/header_parser.rb

Instance Method Summary collapse

Instance Method Details

#delim?(c) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/aws/xray/header_parser.rb', line 40

def delim?(c)
  c == ';'
end

#equal_mark?(c) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/aws/xray/header_parser.rb', line 44

def equal_mark?(c)
  c == '='
end

#parse(header_value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/aws/xray/header_parser.rb', line 7

def parse(header_value)
  h = {}
  key = ''
  value = ''
  value_mode = false
  header_value.chars.each_with_index do |c, i|
    next if space?(c)
    if delim?(c)
      h[key] = value unless key.empty?
      key, value = '', ''
      value_mode = false
      next
    end

    if equal_mark?(c)
      value_mode = true
      next
    end

    if value_mode
      value << c
    else
      key << c
    end
  end
  h[key] = value if !key.empty? && !value.empty?
  h
end

#space?(c) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/aws/xray/header_parser.rb', line 36

def space?(c)
  c == ' '
end