module Excon::Utils

def headers_hash_to_s(headers)

Performs validation on the passed header hash and returns a string representation of the headers
def headers_hash_to_s(headers)
  headers_str = +''
  headers.each do |key, values|
    if key.to_s.match?(/[\r\n]/)
      raise Excon::Errors::InvalidHeaderKey, "#{key.to_s.inspect} contains forbidden \"\\r\" or \"\\n\""
    end
    [values].flatten.each do |value|
      if value.to_s.match?(/[\r\n]/)
        # Don't include the potentially sensitive header value (i.e. authorization token) in the message
        raise Excon::Errors::InvalidHeaderValue, "#{key} header value contains forbidden \"\\r\" or \"\\n\""
      end
      headers_str << key.to_s << ': ' << value.to_s << CR_NL
    end
  end
  headers_str
end