diff --git a/.rubocop.yml b/.rubocop.yml index e12652a..9ce51d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -39,6 +39,8 @@ Style/DoubleNegation: Enabled: false Style/Documentation: + AllowedConstants: + - "Typhoeus" Exclude: - 'spec/**/*' - 'examples/**/*' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a3381e7..25f13cd 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2022-04-13 06:39:06 UTC using RuboCop version 1.27.0. +# on 2022-04-17 22:56:21 UTC using RuboCop version 1.27.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,7 +14,7 @@ Metrics/AbcSize: # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 109 + Max: 107 # Offense count: 2 # Configuration parameters: IgnoredMethods. diff --git a/README.md b/README.md index b2fb8b9..0040ee1 100644 --- a/README.md +++ b/README.md @@ -125,8 +125,8 @@ To release a new version, update the version number in `version.rb`, and then ru - [ ] Better tests for parallel functionality (can port them over from Typhoeus) - [ ] Support block-based configuration like other adapters - [ ] Refactor the adapter a bit to look more like other Faraday 2 adapters (use `connection` etc.) -- [ ] Compression support -- [ ] Reason-phrase parsing support +- [x] Compression support +- [x] Reason-phrase parsing support ## Contributing diff --git a/bin/console b/bin/console index 317ba7c..8a6b71b 100755 --- a/bin/console +++ b/bin/console @@ -2,7 +2,8 @@ # frozen_string_literal: true require 'bundler/setup' -require 'faraday-typhoeus' +require 'faraday' +require 'faraday/typhoeus' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/lib/faraday/adapter/typhoeus.rb b/lib/faraday/adapter/typhoeus.rb index 02e7ecc..eb0a3b3 100644 --- a/lib/faraday/adapter/typhoeus.rb +++ b/lib/faraday/adapter/typhoeus.rb @@ -4,25 +4,9 @@ module Faraday class Adapter - # This class provides the main implementation for your adapter. - # There are some key responsibilities that your adapter should satisfy: - # * Initialize and store internally the client you chose (e.g. Net::HTTP) - # * Process requests and save the response (see `#call`) class Typhoeus < Faraday::Adapter self.supports_parallel = true - # The initialize method is lazy-called ONCE when the connection stack is - # built. See https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb - # - # @param app [#call] the "rack app" wrapped in middleware. See - # https://github.com/lostisland/faraday/blob/master/lib/faraday/rack_builder.rb#L157 - # @param opts [Hash] the options hash with all the options necessary for - # the adapter to correctly configure itself. These are automatically - # stored into `@connection_options` when you call `super`. - def initialize(app = nil, opts = {}, &block) - super(app, opts, &block) - end - # Setup Hydra with provided options. # # @example Setup Hydra. @@ -43,14 +27,6 @@ def call(env) perform_request env @app.call(env) - # NOTE: An adapter `call` MUST return the `env.response`. If - # `save_response` is the last line in your `call` method implementation, - # it will automatically return the response for you. Otherwise, you'll - # need to manually do so. You can do this with any (not both) of the - # following lines: - # * @app.call(env) - # * env.response - # # Finally, it's good practice to rescue client-specific exceptions (e.g. # Timeout, ConnectionFailed, etc...) and re-raise them as Faraday # Errors. Check `Faraday::Error` for a list of all errors. @@ -129,7 +105,9 @@ def typhoeus_request(env) opts = { method: env[:method], body: env[:body], - headers: env[:request_headers] + headers: env[:request_headers], + # https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html + accept_encoding: '' }.merge(@connection_options) ::Typhoeus::Request.new(env[:url].to_s, opts) diff --git a/spec/faraday/adapter/typhoeus_spec.rb b/spec/faraday/adapter/typhoeus_spec.rb index 15765fb..d1c1c48 100644 --- a/spec/faraday/adapter/typhoeus_spec.rb +++ b/spec/faraday/adapter/typhoeus_spec.rb @@ -3,6 +3,8 @@ RSpec.describe Faraday::Adapter::Typhoeus do features :request_body_on_query_methods, :reason_phrase_parse, + # transparent compression IS supported but tests will fail b/c + # webmock is unaware of this # :compression, :streaming, :trace_method @@ -19,6 +21,13 @@ describe '#initialize' do let(:request) { adapter.method(:typhoeus_request).call({}) } + context 'when no options specified' do + let(:adapter) { described_class.new(nil) } + it 'defers to curl on accepted encodings' do + expect(request.options[:accept_encoding]).to eq('') + end + end + context 'when typhoeus request options specified' do let(:adapter) { described_class.new(nil, { forbid_reuse: true, maxredirs: 1 }) }