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)


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

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

#equal_mark?(c) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#parse(header_value) ⇒ Object

XXX: returns error when given invaild header_value Header format document: docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader



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
35
# File 'lib/aws/xray/header_parser.rb', line 8

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
      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)


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

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