rest-client / rest-client

Simple HTTP and REST client for Ruby, inspired by microframework syntax for specifying actions.

Home Page:https://rubydoc.info/github/rest-client/rest-client/master

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Content-Type: application/json` does not default the encoding to UTF-8 as expected

ric2b opened this issue · comments

The IETF RFC defines the default encoding of application/json to be UTF-8 (and always Unicode in general).

RestClient, however, does not respect this default, as can be seen by running the following test:

    it 'handles application/json default as utf-8' do
      body = '{ "abc": 123 }'.force_encoding('ASCII-8BIT')
      stub_request(:get, "www.example.com").to_return(
        :body => body, :status => 200, :headers => {
        'Content-Type' => 'application/json'
      })
      response = RestClient.get "www.example.com"
      expect(response.encoding).to eq Encoding::UTF_8
      expect(response.valid_encoding?).to eq true
    end

I believe it would be an easy fix by adding the necessary logic here, but since the project is unmaintained I'm not going to bother opening a PR and am just leaving this issue here in case it helps someone else save some time investigating the issue.