Does Faraday ignore content-type ?
Closed this issue · 2 comments
otn commented
Does Faraday ignore content-type ?
require "faraday"
a = Faraday.new
u = %w|
http://www.google.com/
http://www.google.com/search?q=AAAAA
http://www.google.co.jp/
|
u.each do |x|
w = a.get(x)
puts "#{w.status} #{w.body.encoding} #{w.headers['Content-Type']} #{x}"
end
==> 302 UTF-8 text/html; charset=UTF-8 http://www.google.com/
==> 200 ASCII-8BIT text/html; charset=ISO-8859-1 http://www.google.com/search?q=AAAAA
==> 200 ASCII-8BIT text/html; charset=Shift_JIS http://www.google.co.jp/
technoweenie commented
Faraday depends on the adapters to return the body with the correct encoding. It'd be really nice if net/http (the default adapter) handled this...
iMacTia commented
Hi @otn, I also think this is something outside of Faraday's box.
Low-level encoding and headers parsing should be managed by the adapter and the result of the code above will probably change if you use another one different from the default one (Net::HTTP).
That said, I see the adapter is actually encoding the first response body in UTF-8, meaning that maybe there's some work under there and it's only in case of exotic values that a default ASCII-8BIT
is returned.