mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-07 00:11:11 -04:00
Merge branch 'typhoeus-parse-blank-header-lines'
This commit is contained in:
commit
d197c18573
@ -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.
|
||||
|
@ -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
|
Loading…
x
Reference in New Issue
Block a user