Skip to content

Commit

Permalink
default compression on in libcurl
Browse files Browse the repository at this point in the history
  • Loading branch information
dleavitt committed Apr 17, 2022
1 parent 61a0022 commit 48bcbed
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Style/DoubleNegation:
Enabled: false

Style/Documentation:
AllowedConstants:
- "Typhoeus"
Exclude:
- 'spec/**/*'
- 'examples/**/*'
Expand Down
4 changes: 2 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 3 additions & 25 deletions lib/faraday/adapter/typhoeus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions spec/faraday/adapter/typhoeus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }) }

Expand Down

0 comments on commit 48bcbed

Please sign in to comment.