Merge branch 'typhoeus-parse-blank-header-lines'

This commit is contained in:
Erik Michaels-Ober 2010-10-15 15:53:56 -07:00
commit d197c18573
2 changed files with 9 additions and 3 deletions

View File

@ -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.

View File

@ -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