Skip to content

Commit

Permalink
Adds support for JSON 2
Browse files Browse the repository at this point in the history
Fixes incompatibility with jruby by isolating brotli
  • Loading branch information
iMacTia committed Aug 18, 2017
1 parent 12bbb51 commit 74236ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
source 'https://rubygems.org'

gem 'brotli', '>= 0.1.8'
gem 'brotli', '>= 0.1.8', platforms: :mri
gem 'hashie', '>= 1.2'
gem 'jruby-openssl', :platforms => :jruby
gem 'json', '< 2'
gem 'jruby-openssl', platforms: :jruby
gem 'json', '< 3'
gem 'multi_xml', '>= 0.5.3'
gem 'rack', '< 2'
gem 'rack-cache', '>= 1.1', '< 1.3'
Expand All @@ -13,8 +13,8 @@ gem 'simple_oauth', '>= 0.1', '< 0.3'
gem 'safe_yaml'

group :test do
gem 'cane', '>= 2.2.2', :platforms => [:mri_19, :mri_20, :mri_21]
gem 'parallel', '< 1.3.4', :platforms => [:mri_19, :mri_20, :mri_21]
gem 'cane', '>= 2.2.2', platforms: [:mri_19, :mri_20, :mri_21]
gem 'parallel', '< 1.3.4', platforms: [:mri_19, :mri_20, :mri_21]
gem 'rspec', '>= 3'
gem 'simplecov', '~> 0.12.0'
gem 'webmock', '< 2'
Expand Down
3 changes: 2 additions & 1 deletion lib/faraday_middleware/gzip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module FaradayMiddleware
# - em_http
class Gzip < Faraday::Middleware
dependency 'zlib'
dependency 'brotli'

ACCEPT_ENCODING = 'Accept-Encoding'.freeze
CONTENT_ENCODING = 'Content-Encoding'.freeze
Expand Down Expand Up @@ -65,6 +64,8 @@ def inflate(body)
end

def brotli_inflate(body)
dependency 'brotli'

Brotli.inflate(body)
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ def process(body, content_type = nil, options = {})
config.expect_with :rspec do |c|
c.syntax = :expect
end

def jruby?
defined?(RUBY_ENGINE) and 'jruby' == RUBY_ENGINE
end
end
2 changes: 1 addition & 1 deletion spec/unit/gzip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
let(:headers) { {'Content-Encoding' => 'br', 'Content-Length' => body.length } }

it_behaves_like 'compressed response'
end
end unless jruby?

context 'identity response' do
let(:body) { uncompressed_body }
Expand Down
4 changes: 1 addition & 3 deletions spec/unit/parse_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
end

it "chokes on invalid json" do
['{!', '"a"', 'true', 'null', '1'].each do |data|
expect{ process(data) }.to raise_error(Faraday::Error::ParsingError)
end
expect{ process('{!') }.to raise_error(Faraday::Error::ParsingError)
end

it "includes the response on the ParsingError instance" do
Expand Down

0 comments on commit 74236ad

Please sign in to comment.