diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 8125e737..b121977c 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -56,9 +56,10 @@ module Faraday def parse_response_headers(header_string) return {} unless header_string && !header_string.empty? Hash[*header_string.split(/\r\n/). - tap { |a| a.shift }. # drop the HTTP status line - map! { |h| h.split(/:\s+/,2) }. # split key and value - map! { |(k, v)| [k.downcase, v] }.flatten!] + tap { |a| a.shift }. # drop the HTTP status line + map { |h| h.split(/:\s+/,2) }. # split key and value + reject { |(k, v)| k.nil? }. # Ignore blank lines + map { |(k, v)| [k.downcase, v] }.flatten] end # TODO: build in support for multipart streaming if typhoeus supports it. diff --git a/test/adapters/typhoeus_test.rb b/test/adapters/typhoeus_test.rb index f1be021c..1fbab525 100644 --- a/test/adapters/typhoeus_test.rb +++ b/test/adapters/typhoeus_test.rb @@ -21,6 +21,11 @@ if Faraday::Adapter::Typhoeus.loaded? headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nLocation: http://sushi.com/\r\n\r\n") assert_equal 'http://sushi.com/', headers['location'] end + + def test_parse_response_headers_parses_blank_lines + headers = @adapter.parse_response_headers("HTTP/1.1 200 OK\r\n\r\nContent-Type: text/html\r\n\r\n") + assert_equal 'text/html', headers['content-type'] + end end end end \ No newline at end of file