Merge pull request #33 from adlan/case-insensitive-header-check
Do a case-insensitive content-type check
This commit is contained in:
commit
1a3928a6e4
|
@ -113,7 +113,7 @@ defmodule Readability do
|
||||||
headers
|
headers
|
||||||
|> Enum.find(
|
|> Enum.find(
|
||||||
{"Content-Type", "text/plain"}, # default
|
{"Content-Type", "text/plain"}, # default
|
||||||
fn({key, _}) -> key == "Content-Type" end)
|
fn({key, _}) -> String.downcase(key) == "content-type" end)
|
||||||
|> elem(1)
|
|> elem(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -66,4 +66,20 @@ defmodule ReadabilityHttpTest do
|
||||||
assert result_html =~ ~r/connected computing devices\".<\/p><\/div><\/div>$/
|
assert result_html =~ ~r/connected computing devices\".<\/p><\/div><\/div>$/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "response with content-type in different case is parsed correctly" do
|
||||||
|
# HTTP header keys are case insensitive (RFC2616 - Section 4.2)
|
||||||
|
url = "https://news.bbc.co.uk/test.html"
|
||||||
|
content = TestHelper.read_fixture("bbc.html")
|
||||||
|
response = %HTTPoison.Response{
|
||||||
|
status_code: 200,
|
||||||
|
headers: [{"content-Type", "text/html; charset=UTF-8"}],
|
||||||
|
body: content}
|
||||||
|
|
||||||
|
with_mock HTTPoison, [get!: fn(_url, _headers, _opts) -> response end] do
|
||||||
|
%Readability.Summary{article_html: result_html} = Readability.summarize(url)
|
||||||
|
|
||||||
|
assert result_html =~ ~r/connected computing devices\".<\/p><\/div><\/div>$/
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue