1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Merge pull request #530 from robdimarco/master

Handle an HTTP Response with a Content-type but no body.
This commit is contained in:
John Nunemaker 2017-05-16 09:20:16 -04:00 committed by GitHub
commit e7f5a5463c
2 changed files with 8 additions and 1 deletions

View file

@ -276,7 +276,7 @@ module HTTParty
end
def encode_with_ruby_encoding(body, charset)
if Encoding.name_list.include?(charset)
if !body.nil? && Encoding.name_list.include?(charset)
body.force_encoding(charset)
else
body

View file

@ -485,6 +485,13 @@ RSpec.describe HTTParty::Request do
expect(resp.body.encoding).to eq(Encoding.find("UTF-8"))
end
it "should process response with a nil body" do
response = stub_response nil
response.initialize_http_header("Content-Type" => "text/html;charset=UTF-8")
resp = @request.perform
expect(resp.body).to be_nil
end
it "should process utf-16 charset with little endian bom correctly" do
@request.options[:assume_utf16_is_big_endian] = true