Skip to content

Commit

Permalink
Merge pull request #528 from 3scale/fix-content-type-with-charset
Browse files Browse the repository at this point in the history
THREESCALE-11063: Fix parsing response if Content-Type contains charset
  • Loading branch information
mayorova committed Jun 3, 2024
2 parents 256e1f3 + 38e3794 commit 28d1619
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/adapters/abstract_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ def self.parse_response(response)

content_type = response.content_type.presence or return body

case Mime::Type.lookup(content_type)
when JSON_TYPE then JSON.parse(body)
else raise InvalidResponseError.new response: response, message: 'Unknown Content-Type'
if Mime::Type.lookup(content_type).match? JSON_TYPE
JSON.parse(body)
else
raise InvalidResponseError.new response: response, message: 'Unknown Content-Type'
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/adapters/abstract_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,15 @@ class AbstractAdapterTest < ActiveSupport::TestCase
assert_nil subject.new('https://example.com').authentication
end
end

test 'content-type with charset' do
content_type = 'application/json;charset=UTF-8'
stub_request(:get, 'https://example.com/.well-known/openid-configuration').
to_return(body: '{}', headers: {'Content-Type': content_type})
stub_request(:post, 'https://example.com').to_return(status: 200, body: '{"access_token": "test"}', headers: {'Content-Type': content_type})

assert_nothing_raised do
subject.new('https://example.com').authentication
end
end
end

0 comments on commit 28d1619

Please sign in to comment.