Class: Playwright::RawHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/raw_headers.rb

Instance Method Summary collapse

Constructor Details

#initialize(headers_array) ⇒ RawHeaders

Returns a new instance of RawHeaders.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/playwright/raw_headers.rb', line 3

def initialize(headers_array)
  h_array = []
  h_map = {}
  headers_array.each do |header|
    name = header['name']
    key = name.downcase
    value = header['value']

    h_array << [name, value]
    h_map[key] ||= []
    h_map[key] << value
  end

  @headers_array = h_array
  @headers_map = h_map
end

Instance Method Details

#get(name) ⇒ String|nil

Returns:

  • (String|nil)


21
22
23
24
25
26
27
28
29
# File 'lib/playwright/raw_headers.rb', line 21

def get(name)
  key = name.downcase
  values = @headers_map[key]
  if values
    join(key, values)
  else
    nil
  end
end

#get_all(name) ⇒ Array<String>

Returns:

  • (Array<String>)


32
33
34
35
36
37
38
39
# File 'lib/playwright/raw_headers.rb', line 32

def get_all(name)
  values = @headers_map[name.downcase]
  if values
    values.dup
  else
    []
  end
end

#headersObject



41
42
43
44
45
# File 'lib/playwright/raw_headers.rb', line 41

def headers
  @headers_map.map do |key, values|
    [key, join(key, values)]
  end.to_h
end

#headers_arrayObject



47
48
49
50
51
# File 'lib/playwright/raw_headers.rb', line 47

def headers_array
  @headers_array.map do |name, value|
    { name: name, value: value }
  end
end