-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
honor Content-Type charset #6
Comments
I wrote some code to handle the charset (see below). I really have no idea how to write the tests, unfortunately. I haven't used RSpec before. I see a bunch of nested tests but I'm not sure how to stub responses inside an adapter test. Any pointers? def encoded_body(http_response)
body = http_response.body || +''
if encoding = encoding_for(http_response)
if body.encoding != encoding
body = body.dup if body.frozen?
body.force_encoding(encoding)
end
end
body
end
def encoding_for(http_response)
if content_type = http_response['Content-Type']
if encoding = content_type[/\bcharset=\s*(.+?)\s*(;|$)/, 1]
Encoding.find(encoding) rescue nil
end
end
end |
Also, I am unfamiliar with this syntax |
Hi @gurgeous thanks for raising this and doing some initial research!
The only "strange" thing in there I can see is the |
I've run into this issue, and it looks like others have as well:
lostisland/faraday#139
lostisland/faraday#443
It would be easy to handle charset, at least on par with other adapters. What do you think? Happy to put together a PR if there's interest.
The text was updated successfully, but these errors were encountered: