Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

handle more than one Set-Cookie header

  • Loading branch information...
commit a4f65034c295dd32bbdd9fc1ba4810245669885b 1 parent aaf375c
Steffen Roller authored

Showing 1 changed file with 25 additions and 3 deletions. Show diff stats Hide diff stats

  1. +25 3 lib/httpi/adapter/httpclient.rb
28 lib/httpi/adapter/httpclient.rb
@@ -84,15 +84,37 @@ def setup_ssl_auth(ssl)
84 84 unless ssl.verify_mode == :none
85 85 client.ssl_config.client_cert = ssl.cert
86 86 client.ssl_config.client_key = ssl.cert_key
87   - client.ssl_config.client_ca = ssl.ca_cert if ssl.ca_cert_file
  87 + # client.ssl_config.client_ca = ssl.ca_cert if ssl.ca_cert_file
  88 + client.ssl_config.set_trust_ca(ssl.ca_cert_file) if ssl.ca_cert_file
88 89 end
89 90 client.ssl_config.verify_mode = ssl.openssl_verify_mode
90 91 end
91 92
  93 + #
  94 + # Steffen Roller <steffen@rollers.de>
  95 + #
  96 + # response.header.all is an array of 2-element arrays
  97 + # some headers eg. "Set-Cookie" can occur more than one
  98 + # To convert the array of arrays into a hash
  99 + # we iterate over the array. If the first element already
  100 + # exists in the hash we convert the entry into an array.
  101 + #
92 102 def respond_with(response)
93   - Response.new response.code, Hash[*response.header.all.flatten], response.content
  103 + header_hash = {}
  104 + response.header.all.each do |item|
  105 + if header_hash.has_key?(item[0])
  106 + if header_hash[item[0]].is_a? Array
  107 + header_hash[item[0]] << item[1]
  108 + else
  109 + header_hash[item[0]] = [header_hash[item[0]], item[1]]
  110 + end
  111 + else
  112 + header_hash[item[0]] = item[1]
  113 + end
  114 + end
  115 + # Response.new response.code, Hash[*response.header.all.flatten], response.content
  116 + Response.new response.code, header_hash, response.content
94 117 end
95   -
96 118 end
97 119 end
98 120 end

0 comments on commit a4f6503

Please sign in to comment.
Something went wrong with that request. Please try again.