class Ingenico::Connect::SDK::RequestHeader
Represents HTTP request headers Each header is immutable has a name
and value
attribute
@attr_reader [String] name HTTP header name @attr_reader [String] value HTTP header value
Attributes
name[R]
value[R]
Public Class Methods
get_header(headers, header_name)
click to toggle source
Return the {Ingenico::Connect::SDK::ResponseHeader} that goes by the given header_name, If this Response does not contain a header with the given name, return nil instead
# File lib/ingenico/connect/sdk/request_header.rb, line 28 def self.get_header(headers, header_name) selected_headers = headers.select { |h| h.name == header_name } if selected_headers.nil? || selected_headers.length == 0 return nil else return selected_headers[0] end end
get_header_value(headers, header_name)
click to toggle source
Returns the header value of the header that goes by the given header_name, If this response does not contain a header with the given name, return nil instead
# File lib/ingenico/connect/sdk/request_header.rb, line 39 def self.get_header_value(headers, header_name) header = get_header(headers, header_name) return (if header.nil? then nil else header.value end) end
new(name, value)
click to toggle source
Create a new header using the name and value given as parameters.
# File lib/ingenico/connect/sdk/request_header.rb, line 11 def initialize(name, value) if name.nil? || name.strip.empty? raise ArgumentError.new('name is required') end @name = name @value = normalize_value(value) end
Public Instance Methods
to_s()
click to toggle source
# File lib/ingenico/connect/sdk/request_header.rb, line 22 def to_s "#{name}:#{value}" end
Private Instance Methods
normalize_value(value)
click to toggle source
# File lib/ingenico/connect/sdk/request_header.rb, line 46 def normalize_value(value) if value.nil? || value.empty? return value end # Replace all sequences of whitespace*-linebreak-whitespace* into a single linebreak-space # This will ensure that: # - no line ends with whitespace, because this causes authentication failures # - each line starts with a single whitespace, so it is a valid header value value.gsub(/[\s&&[^\r\n]]*(\r?\n)[\s&&[^\r\n]]*/, '\1 ') end