New Upstream Release - ruby-faraday
Ready changes
Summary
Merged new upstream version: 2.7.4 (was: 2.7.1).
Resulting package
Built on 2023-01-31T15:43 (took 2m14s)
The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:
apt install -t fresh-releases ruby-faraday
Lintian Result
Diff
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 99d86d6..07a9a88 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -43,7 +43,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- ruby: [ '2.6', '2.7', '3.0', '3.1' ]
+ ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2' ]
experimental: [false]
include:
- ruby: head
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index a66ce17..87d206f 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- name: Set up Ruby 2.7
- uses: actions/setup-ruby@v1
+ uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
diff --git a/LICENSE.md b/LICENSE.md
index e6ed1b9..3877615 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,4 +1,4 @@
-Copyright (c) 2009-2022 Rick Olson, Zack Hobson
+Copyright (c) 2009-2023 Rick Olson, Zack Hobson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
diff --git a/README.md b/README.md
index 4bf79a6..ef6ad23 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,6 @@
[![GitHub Actions CI](https://github.com/lostisland/faraday/workflows/CI/badge.svg)](https://github.com/lostisland/faraday/actions?query=workflow%3ACI)
[![GitHub Discussions](https://img.shields.io/github/discussions/lostisland/faraday?logo=github)](https://github.com/lostisland/faraday/discussions)
-
Faraday is an HTTP client library abstraction layer that provides a common interface over many
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when processing the request/response cycle.
You probably don't want to use Faraday directly in your project, as it will lack an actual client library to perform
@@ -42,14 +41,15 @@ Open the issues page and check for the `help wanted` label!
But before you start coding, please read our [Contributing Guide][contributing]
## Copyright
-© 2009 - 2022, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
-[awesome]: https://github.com/lostisland/awesome-faraday/#adapters
-[website]: https://lostisland.github.io/faraday
+© 2009 - 2023, the [Faraday Team][faraday_team]. Website and branding design by [Elena Lo Piccolo](https://elelopic.design).
+
+[awesome]: https://github.com/lostisland/awesome-faraday/#adapters
+[website]: https://lostisland.github.io/faraday
[faraday_team]: https://lostisland.github.io/faraday/team
[contributing]: https://github.com/lostisland/faraday/blob/master/.github/CONTRIBUTING.md
-[apidoc]: https://www.rubydoc.info/github/lostisland/faraday
-[actions]: https://github.com/lostisland/faraday/actions
-[jruby]: http://jruby.org/
-[rubinius]: http://rubini.us/
-[license]: LICENSE.md
+[apidoc]: https://www.rubydoc.info/github/lostisland/faraday
+[actions]: https://github.com/lostisland/faraday/actions
+[jruby]: http://jruby.org/
+[rubinius]: http://rubini.us/
+[license]: LICENSE.md
diff --git a/debian/changelog b/debian/changelog
index e328244..0c4e61e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+ruby-faraday (2.7.4-1) UNRELEASED; urgency=low
+
+ * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk> Tue, 31 Jan 2023 15:42:00 -0000
+
ruby-faraday (2.7.1-1) experimental; urgency=medium
[ Debian Janitor ]
diff --git a/debian/patches/remove-coveralls.patch b/debian/patches/remove-coveralls.patch
index 1c16699..0768132 100644
--- a/debian/patches/remove-coveralls.patch
+++ b/debian/patches/remove-coveralls.patch
@@ -1,8 +1,10 @@
We don't care about coverage and ignore test failure because coverage is low
---- a/spec/spec_helper.rb
-+++ b/spec/spec_helper.rb
-@@ -27,7 +27,7 @@
+Index: ruby-faraday.git/spec/spec_helper.rb
+===================================================================
+--- ruby-faraday.git.orig/spec/spec_helper.rb
++++ ruby-faraday.git/spec/spec_helper.rb
+@@ -27,7 +27,7 @@ SimpleCov.formatters = [SimpleCov::Forma
SimpleCov.start do
add_filter '/spec/'
minimum_coverage 84
diff --git a/debian/patches/require-faraday.patch b/debian/patches/require-faraday.patch
index 0ac00b9..5a238ed 100644
--- a/debian/patches/require-faraday.patch
+++ b/debian/patches/require-faraday.patch
@@ -1,7 +1,9 @@
Add explicit require for faraday
---- a/spec/spec_helper.rb
-+++ b/spec/spec_helper.rb
+Index: ruby-faraday.git/spec/spec_helper.rb
+===================================================================
+--- ruby-faraday.git.orig/spec/spec_helper.rb
++++ ruby-faraday.git/spec/spec_helper.rb
@@ -16,6 +16,7 @@
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
diff --git a/debian/patches/skip-test-failing-in-ubuntu.patch b/debian/patches/skip-test-failing-in-ubuntu.patch
index 1ea877f..7e53a01 100644
--- a/debian/patches/skip-test-failing-in-ubuntu.patch
+++ b/debian/patches/skip-test-failing-in-ubuntu.patch
@@ -13,11 +13,11 @@ Forwarded: not-needed
spec/faraday/connection_spec.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
-diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb
-index 4f51f56..76dd320 100644
---- a/spec/faraday/connection_spec.rb
-+++ b/spec/faraday/connection_spec.rb
-@@ -403,7 +403,7 @@ RSpec.describe Faraday::Connection do
+Index: ruby-faraday.git/spec/faraday/connection_spec.rb
+===================================================================
+--- ruby-faraday.git.orig/spec/faraday/connection_spec.rb
++++ ruby-faraday.git/spec/faraday/connection_spec.rb
+@@ -458,7 +458,7 @@ RSpec.describe Faraday::Connection do
with_env 'HTTP_PROXY' => 'http://localhost:8888/' do
expect(conn.proxy).to be_nil
end
diff --git a/docs/_config.yml b/docs/_config.yml
index bce570b..0f63526 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -11,7 +11,7 @@ theme_settings:
# email: your-email@example.com
description: >-
Simple, but flexible HTTP client library, with support for multiple backends
- footer_text: "© 2009 - 2022, the <a class=\"body-link\" href=\"/faraday/team\">Faraday Team</a>. Website and branding design by <a href=\"https://elelopic.design\" target=\"_blank\">Elena Lo Piccolo</a>."
+ footer_text: "© 2009 - 2023, the <a class=\"body-link\" href=\"/faraday/team\">Faraday Team</a>. Website and branding design by <a href=\"https://elelopic.design\" target=\"_blank\">Elena Lo Piccolo</a>."
# Icons
github: 'lostisland/faraday'
diff --git a/docs/adapters/index.md b/docs/adapters/index.md
index aaba0d0..e75cfe3 100644
--- a/docs/adapters/index.md
+++ b/docs/adapters/index.md
@@ -12,7 +12,7 @@ either globally or per Faraday Connection through the configuration block.
For example, consider using `httpclient` as an adapter. Note that [faraday-httpclient](https://github.com/lostisland/faraday-httpclient) must be installed beforehand.
-If you wants to configure it globally, do the following:
+If you want to configure it globally, do the following:
```ruby
require 'faraday'
diff --git a/docs/middleware/index.md b/docs/middleware/index.md
index 0b2df84..4a0655d 100644
--- a/docs/middleware/index.md
+++ b/docs/middleware/index.md
@@ -49,6 +49,40 @@ therefore be last.
![Middleware](../assets/img/middleware.png)
+This is what makes things like the "retry middleware" possible.
+It doesn't really matter if the middleware was registered as a request or a response one, the only thing that matter is how they're added to the stack.
+
+Say you have the following:
+
+```ruby
+Faraday.new(...) do |conn|
+ conn.request :authorization
+ conn.response :json
+ conn.response :parse_dates
+end
+```
+
+This will result into a middleware stack like this:
+
+```ruby
+authorization do
+ # authorization request hook
+ json do
+ # json request hook
+ parse_dates do
+ # parse_dates request hook
+ response = adapter.perform(request)
+ # parse_dates response hook
+ end
+ # json response hook
+ end
+ # authorization response hook
+end
+```
+
+In this example, you can see that `parse_dates` is the LAST middleware processing the request, and the FIRST middleware processing the response.
+This is why it's important for the adapter to always be at the end of the middleware list.
+
### Using Middleware
Calling `use` is the most basic way to add middleware to your stack, but most
diff --git a/docs/middleware/response/logger.md b/docs/middleware/response/logger.md
index d2445ff..4cc52e4 100644
--- a/docs/middleware/response/logger.md
+++ b/docs/middleware/response/logger.md
@@ -96,7 +96,8 @@ end
You can also provide a custom formatter to control how requests, responses and errors are logged.
Any custom formatter MUST implement the `request` and `response` method, with one argument which
will be passed being the Faraday environment.
-Any custom formatter CAN implement the `error` method, with one argument which will be passed being the Faraday error.
+Any custom formatter CAN implement the `exception` method,
+with one argument which will be passed being the exception (StandardError).
If you make your formatter inheriting from `Faraday::Logging::Formatter`,
then the methods `debug`, `info`, `warn`, `error` and `fatal` are automatically delegated to the logger.
@@ -112,8 +113,8 @@ class MyFormatter < Faraday::Logging::Formatter
info('Response') { 'Response Received' }
end
- def error(error)
- # Build a custom message using `error`
+ def exception(exc)
+ # Build a custom message using `exc`
info('Error') { 'Error Raised' }
end
end
diff --git a/lib/faraday/adapter.rb b/lib/faraday/adapter.rb
index f3e6af7..a581166 100644
--- a/lib/faraday/adapter.rb
+++ b/lib/faraday/adapter.rb
@@ -78,8 +78,7 @@ module Faraday
# @param type [Symbol] Describes which timeout setting to get: :read,
# :write, or :open.
# @param options [Hash] Hash containing Symbol keys like :timeout,
- # :read_timeout, :write_timeout, :open_timeout, or
- # :timeout
+ # :read_timeout, :write_timeout, or :open_timeout
#
# @return [Integer, nil] Timeout duration in seconds, or nil if no timeout
# has been set.
diff --git a/lib/faraday/adapter/test.rb b/lib/faraday/adapter/test.rb
index b8a5b28..b0913ad 100644
--- a/lib/faraday/adapter/test.rb
+++ b/lib/faraday/adapter/test.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true
+require 'timeout'
+
module Faraday
class Adapter
# @example
@@ -238,7 +240,7 @@ module Faraday
end
def body_match?(request_body)
- return true if body.to_s.size.zero?
+ return true if body.to_s.empty?
case body
when Proc
@@ -277,11 +279,22 @@ module Faraday
end
block_arity = stub.block.arity
+ params = if block_arity >= 0
+ [env, meta].take(block_arity)
+ else
+ [env, meta]
+ end
+
+ timeout = request_timeout(:open, env[:request])
+ timeout ||= request_timeout(:read, env[:request])
+
status, headers, body =
- if block_arity >= 0
- stub.block.call(*[env, meta].take(block_arity))
+ if timeout
+ ::Timeout.timeout(timeout, Faraday::TimeoutError) do
+ stub.block.call(*params)
+ end
else
- stub.block.call(env, meta)
+ stub.block.call(*params)
end
# We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts.
diff --git a/lib/faraday/connection.rb b/lib/faraday/connection.rb
index b86245d..4a4a73c 100644
--- a/lib/faraday/connection.rb
+++ b/lib/faraday/connection.rb
@@ -220,7 +220,7 @@ module Faraday
# @yield [Faraday::Request] for further request customizations
# @return [Faraday::Response]
def options(*args)
- return @options if args.size.zero?
+ return @options if args.empty?
url, params, headers = *args
run_request(:options, url, nil, headers) do |request|
@@ -261,14 +261,13 @@ module Faraday
# @param headers [Hash, nil] unencoded HTTP header key/value pairs.
#
# @example
- # # TODO: Make it a PUT example
- # conn.post '/items', data, content_type: 'application/json'
+ # conn.put '/products/123', data, content_type: 'application/json'
#
- # # Simple ElasticSearch indexing sample.
- # conn.post '/twitter/tweet' do |req|
- # req.headers[:content_type] = 'application/json'
- # req.params[:routing] = 'kimchy'
- # req.body = JSON.generate(user: 'kimchy', ...)
+ # # Star a gist.
+ # conn.put 'https://api.github.com/gists/GIST_ID/star' do |req|
+ # req.headers['Accept'] = 'application/vnd.github+json'
+ # req.headers['Authorization'] = 'Bearer <YOUR-TOKEN>'
+ # req.headers['X-GitHub-Api-Version'] = '2022-11-28'
# end
#
# @yield [Faraday::Request] for further request customizations
@@ -471,10 +470,10 @@ module Faraday
def build_exclusive_url(url = nil, params = nil, params_encoder = nil)
url = nil if url.respond_to?(:empty?) && url.empty?
base = url_prefix.dup
- if url && base.path && base.path !~ %r{/$}
+ if url && !base.path.end_with?('/')
base.path = "#{base.path}/" # ensure trailing slash
end
- url = url.to_s.gsub(':', '%3A') if url && URI.parse(url.to_s).opaque
+ url = url.to_s.gsub(':', '%3A') if URI.parse(url.to_s).opaque
uri = url ? base + url : base
if params
uri.query = params.to_query(params_encoder || options.params_encoder)
diff --git a/lib/faraday/logging/formatter.rb b/lib/faraday/logging/formatter.rb
index 863cdc0..ae7e6ce 100644
--- a/lib/faraday/logging/formatter.rb
+++ b/lib/faraday/logging/formatter.rb
@@ -37,16 +37,16 @@ module Faraday
log_body('response', env[:body]) if env[:body] && log_body?(:response)
end
- def error(error)
+ def exception(exc)
return unless log_errors?
- error_log = proc { error.full_message }
+ error_log = proc { exc.full_message }
public_send(log_level, 'error', &error_log)
- log_headers('error', error.response_headers) if error.respond_to?(:response_headers) && log_headers?(:error)
- return unless error.respond_to?(:response_body) && error.response_body && log_body?(:error)
+ log_headers('error', exc.response_headers) if exc.respond_to?(:response_headers) && log_headers?(:error)
+ return unless exc.respond_to?(:response_body) && exc.response_body && log_body?(:error)
- log_body('error', error.response_body)
+ log_body('error', exc.response_body)
end
def filter(filter_word, filter_replacement)
diff --git a/lib/faraday/options/env.rb b/lib/faraday/options/env.rb
index 1446f67..02cb265 100644
--- a/lib/faraday/options/env.rb
+++ b/lib/faraday/options/env.rb
@@ -15,13 +15,19 @@ module Faraday
# @return [Hash] options for configuring the request.
# Options for configuring the request.
#
- # - `:timeout` open/read timeout Integer in seconds
- # - `:open_timeout` - read timeout Integer in seconds
- # - `:on_data` - Proc for streaming
- # - `:proxy` - Hash of proxy options
- # - `:uri` - Proxy Server URI
- # - `:user` - Proxy server username
- # - `:password` - Proxy server password
+ # - `:timeout` - time limit for the entire request (Integer in
+ # seconds)
+ # - `:open_timeout` - time limit for just the connection phase (e.g.
+ # handshake) (Integer in seconds)
+ # - `:read_timeout` - time limit for the first response byte received from
+ # the server (Integer in seconds)
+ # - `:write_timeout` - time limit for the client to send the request to the
+ # server (Integer in seconds)
+ # - `:on_data` - Proc for streaming
+ # - `:proxy` - Hash of proxy options
+ # - `:uri` - Proxy server URI
+ # - `:user` - Proxy server username
+ # - `:password` - Proxy server password
#
# @!attribute request_headers
# @return [Hash] HTTP Headers to be sent to the server.
diff --git a/lib/faraday/response.rb b/lib/faraday/response.rb
index 3dd1bc5..d1fa932 100644
--- a/lib/faraday/response.rb
+++ b/lib/faraday/response.rb
@@ -61,7 +61,8 @@ module Faraday
def to_hash
{
status: env.status, body: env.body,
- response_headers: env.response_headers
+ response_headers: env.response_headers,
+ url: env.url
}
end
diff --git a/lib/faraday/response/logger.rb b/lib/faraday/response/logger.rb
index 422e32b..d464146 100644
--- a/lib/faraday/response/logger.rb
+++ b/lib/faraday/response/logger.rb
@@ -27,8 +27,8 @@ module Faraday
@formatter.response(env)
end
- def on_error(error)
- @formatter.error(error) if @formatter.respond_to?(:error)
+ def on_error(exc)
+ @formatter.exception(exc) if @formatter.respond_to?(:exception)
end
end
end
diff --git a/lib/faraday/version.rb b/lib/faraday/version.rb
index 9479a99..8a2d615 100644
--- a/lib/faraday/version.rb
+++ b/lib/faraday/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module Faraday
- VERSION = '2.7.1'
+ VERSION = '2.7.4'
end
diff --git a/spec/faraday/adapter/test_spec.rb b/spec/faraday/adapter/test_spec.rb
index bdeb6cd..117bb78 100644
--- a/spec/faraday/adapter/test_spec.rb
+++ b/spec/faraday/adapter/test_spec.rb
@@ -410,4 +410,33 @@ RSpec.describe Faraday::Adapter::Test do
end
end
end
+
+ describe 'request timeout' do
+ subject(:request) do
+ connection.get('/sleep') do |req|
+ req.options.timeout = timeout
+ end
+ end
+
+ before do
+ stubs.get('/sleep') do
+ sleep(0.01)
+ [200, {}, '']
+ end
+ end
+
+ context 'when request is within timeout' do
+ let(:timeout) { 1 }
+
+ it { expect(request.status).to eq 200 }
+ end
+
+ context 'when request is too slow' do
+ let(:timeout) { 0.001 }
+
+ it 'raises an exception' do
+ expect { request }.to raise_error(Faraday::TimeoutError)
+ end
+ end
+ end
end
diff --git a/spec/faraday/connection_spec.rb b/spec/faraday/connection_spec.rb
index 05d9c28..d4ccb23 100644
--- a/spec/faraday/connection_spec.rb
+++ b/spec/faraday/connection_spec.rb
@@ -310,6 +310,21 @@ RSpec.describe Faraday::Connection do
expect(uri.to_s).to eq('http://service.com/api/service%3Asearch?limit=400')
end
end
+
+ context 'with a custom `default_uri_parser`' do
+ let(:url) { 'http://httpbingo.org' }
+ let(:parser) { Addressable::URI }
+
+ around do |example|
+ with_default_uri_parser(parser) do
+ example.run
+ end
+ end
+
+ it 'does not raise error' do
+ expect { conn.build_exclusive_url('/nigiri') }.not_to raise_error
+ end
+ end
end
describe '#build_url' do
diff --git a/spec/faraday/response/logger_spec.rb b/spec/faraday/response/logger_spec.rb
index 674430e..9f16adf 100644
--- a/spec/faraday/response/logger_spec.rb
+++ b/spec/faraday/response/logger_spec.rb
@@ -68,7 +68,7 @@ RSpec.describe Faraday::Response::Logger do
context 'when no route' do
it 'delegates logging to the formatter' do
expect(formatter).to receive(:request).with(an_instance_of(Faraday::Env))
- expect(formatter).to receive(:error).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
+ expect(formatter).to receive(:exception).with(an_instance_of(Faraday::Adapter::Test::Stubs::NotFound))
expect { conn.get '/noroute' }.to raise_error(Faraday::Adapter::Test::Stubs::NotFound)
end
diff --git a/spec/faraday/response_spec.rb b/spec/faraday/response_spec.rb
index 1715947..e3e2c23 100644
--- a/spec/faraday/response_spec.rb
+++ b/spec/faraday/response_spec.rb
@@ -4,7 +4,7 @@ RSpec.describe Faraday::Response do
subject { Faraday::Response.new(env) }
let(:env) do
- Faraday::Env.from(status: 404, body: 'yikes',
+ Faraday::Env.from(status: 404, body: 'yikes', url: Faraday::Utils.URI('https://lostisland.github.io/faraday'),
response_headers: { 'Content-Type' => 'text/plain' })
end
@@ -30,6 +30,7 @@ RSpec.describe Faraday::Response do
it { expect(hash[:status]).to eq(subject.status) }
it { expect(hash[:response_headers]).to eq(subject.headers) }
it { expect(hash[:body]).to eq(subject.body) }
+ it { expect(hash[:url]).to eq(subject.env.url) }
end
describe 'marshal serialization support' do
@@ -45,6 +46,7 @@ RSpec.describe Faraday::Response do
it { expect(loaded.env[:body]).to eq(env[:body]) }
it { expect(loaded.env[:response_headers]).to eq(env[:response_headers]) }
it { expect(loaded.env[:status]).to eq(env[:status]) }
+ it { expect(loaded.env[:url]).to eq(env[:url]) }
end
describe '#on_complete' do