211 Commits

Author SHA1 Message Date
Yutaka Kamei
edd8cc513d
Fix Faraday::Response#to_hash when request is not finished yet (#1639) 2025-09-28 11:20:21 +01:00
Tyler Hunt
0e008c584d
Use newer Unprocessable Content naming for 422 (#1638) 2025-09-21 11:50:36 +01:00
Christian Schmidt
fd81a731fb
Convert strings to UTF-8 (#1624) 2025-09-20 17:14:14 +01:00
Matt
cf32578f25
Improve error handling logic and add missing test coverage (#1633) 2025-07-25 13:18:53 +01:00
Niels Buus
ad8fe1e89a
Include HTTP method and URL in Faraday::Error messages for improved exception log transparency (#1628) 2025-07-04 14:09:46 +01:00
Robert Keresnyei
b63eb9121f
Logger middleware default options (#1618) 2025-04-25 15:20:50 +02:00
Benjamin Fleischer
919dc8fdb3
feat(ssl options): support SNI hostname (#1615) 2025-04-08 21:16:16 +01:00
Hiroaki Osawa
cd1c44a4aa
Fix thread safety issue by avoiding mutation of proxy options hash (#1617) 2025-04-08 13:53:16 +01:00
kodram
529b5b043e
Formatting the log using parameter progname for the logger (#1606) 2024-12-09 10:45:36 +00:00
Mamoru TASAKA
b7b2bc19e9 [TEST] fix compatibility with ruby 3.4.0dev
ruby 3.4 changes Hash#inspect formatting as:
https://bugs.ruby-lang.org/issues/20433

Closes #1602
2024-12-03 08:47:00 +01:00
Clemens Kofler
98d5adf924
Make RaiseError middleware configurable to not raise error on certain status codes (e.g. 404) (#1590) 2024-09-13 15:08:50 +01:00
womblep
9056eccea6
Add ciphers attribute to SSLOptions (#1582) 2024-08-24 11:25:57 +01:00
Ryan McNeil
d83a2818e7
Introduce Middleware DEFAULT_OPTIONS with Application and Instance Configurability (#1572) 2024-07-05 19:30:43 +01:00
ykrods
d8bfca25fa
Merge relative url without escaping (#1569) 2024-06-18 09:50:41 +01:00
Max Rozenoer
04515f38b3
Support default json decoder even when nil responds to :load (#1563)
In Rails (some versions at least), nil responds to `:load` (via ActiveSupport::Dependencies::Loadable mixin).
Enable default json decoder to work in this case
2024-06-05 15:06:16 +01:00
Masato Nakamura
6d82d716c2
Fix compatibility with Ruby 3.4.0-preview1 (#1560) 2024-05-24 15:50:52 +01:00
Vitali Semenyuk
c9cc1b30ec Make dig method case-insensitive in Faraday::Utils::Headers 2024-04-02 14:37:59 +02:00
dependabot[bot]
cd2cdfd446
Update rack requirement from ~> 2.2 to ~> 3.0 (#1549) 2024-01-20 16:53:12 +00:00
Mattia Giuffrida
f0f549d7ef Fix Rubocop offenses 2023-12-28 18:09:17 +01:00
Igor Tikhomirov
1e81e2c71a
Configurable JSON encoders and decoders (#1539) 2023-12-20 09:35:08 +00:00
Daniel Pepper
63ba2aaf0c 429 error 2023-10-21 01:45:30 +02:00
Clayton Passmore
5ccddaafef
Add option for omitting request data from Faraday exceptions (#1526) 2023-09-12 16:38:01 +01:00
Olle Jonsson
230fa1b1f5 Format code with less indent 2023-08-15 08:58:34 +02:00
Koichi ITO
7ce686503a Fix a test failure using Ruby 3.3.0dev
This PR fixes the following test failure using Ruby 3.3.0dev:

```console
$ ruby -v
ruby 3.3.0dev (2023-08-14T15:48:39Z master 52837fcec2) [x86_64-darwin22]
$ bundle exec rspec spec/faraday_spec.rb

Randomized with seed 57031

Faraday
  has a version number
  proxies to default_connection
    uses method_missing on Faraday if there is no proxyable method (FAILED - 1)
    proxies methods that exist on the default_connection
    proxied methods can be accessed

Failures:

  1) Faraday proxies to default_connection uses method_missing on Faraday if there is no proxyable method
     Failure/Error:
       expect { Faraday.this_method_does_not_exist }.to raise_error(
         NoMethodError, expected_message
       )

       expected NoMethodError with "undefined method `this_method_does_not_exist' for Faraday:Module",
       got #<NoMethodError: undefined method `this_method_does_not_exist' for module Faraday> with backtrace:
         # ./lib/faraday.rb:147:in `method_missing'
         # ./spec/faraday_spec.rb:27:in `block (4 levels) in <top (required)>'
         # ./spec/faraday_spec.rb:27:in `block (3 levels) in <top (required)>'
     # ./spec/faraday_spec.rb:27:in `block (3 levels) in <top (required)>'
```

That error message has been changed by https://github.com/ruby/ruby/commit/e7b8d32e in Ruby 3.3.0dev.

cf. https://bugs.ruby-lang.org/issues/18285

So the test error message is changed:

Ruby 3.2 or lower:

```
undefined method `this_method_does_not_exist' for Faraday:Module
```

Ruby 3.3.0dev:

```
NoMethodError: undefined method `this_method_does_not_exist' for module Faraday
```
2023-08-15 08:52:00 +02:00
Sebastian Cohnen
b47e22bf5d adds Faraday::Response::RaiseError for HTTP 408 when using raise error middleware 2023-06-29 09:05:18 +02:00
Eike Send
990799a850
Fix: Logging headers & errors fails when ConnectionFailed is raised (#1512) 2023-06-28 10:17:24 +01:00
Mattia Giuffrida
b54e7aefcc Fix implementation of Faraday::Error helpers.
Fix #1509
2023-06-19 08:30:58 +02:00
TATSUNO “Taz” Yasuhiro
98947e6853
ProxyOptions should treat empty string as nil (#1493) 2023-05-23 16:29:22 +01:00
Yutaka Kamei
6d37ef7e3c
Encode false to "false" in Faraday::Request::Json (#1504)
Previously, `Faraday::Request::Json` doesn't encode the value `false`
while it encodes `true` to `"true"`.

This patch fixes the inconsistent behavior to make the middleware encode
`false` to `"false"`.
2023-05-23 16:19:20 +01:00
Bart de Water
39f1b35db6
Subclass Options structs using a block (#1489)
As recommended on https://ruby-doc.org/core-2.2.2/Struct.html#method-c-new and https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Style/StructInheritance

Has the nice side-effect of making the methods defined by Struct.new discoverable by Tapioca.

Using the @!parse directive to ensure YARD doesn't collapse the separate pages into constants under the Faraday module
2023-02-04 08:53:51 +00:00
Matt
2b9a6241c6
Use Uri.parse instead of Utils.URI (#1485)
Utils.URI can be configured to use a different parser and return an object that "behaves like a URI". However, `opaque` is not available in other objects (e.g. Addressable::URI), so in this instance we need to use URI.

Fixes #1484
2023-01-20 14:53:38 +00:00
Aaron Stillwell
bf3ed115fa
Add URL to to_hash in Faraday::Response (#1475)
Co-authored-by: Matt <iMacTia@users.noreply.github.com>
2023-01-16 15:59:23 +00:00
Matt
c02a104469
Rename Faraday::Logger::Formatter#error to #exception (#1468)
This is because #error is already delegated to the internal Logger, and could cause an infinite loop when the log_level is set to "error".

Fixes #1467
2022-12-14 09:48:10 +00:00
Daniel Pepper
1914d594c4 test adapter timeout 2022-12-09 17:07:19 +01:00
epaew
12bab73ec3 Formatter: make errors' logging controllable. 2022-11-14 17:31:46 +01:00
epaew
5d28006566 Feature: Allows logging of errors that raised in adapter or other middleware. 2022-11-14 17:31:46 +01:00
Yutaka Kamei
ebdcee2b6e
Utils::Headers: Convert self[key] to a String with #<< on #add_parsed (#1459) 2022-11-10 13:27:19 +00:00
Joe Swatosh
e1dbdf065e
Forward the env to Request::Authorization#header_from (#1450) 2022-10-03 13:20:07 +01:00
Matt
43d6797770
Enables and fixes all new cops. (#1443) 2022-08-08 15:46:54 +01:00
Mattia Giuffrida
1a5b794b88 Disable new streaming API specific tests 2022-08-08 12:23:09 +01:00
Mattia Giuffrida
6799f5852d Introduce new streaming API (#1439)
* Backwards-compatible
* Allow adapters to provide response info to on_call block
* Provide `stream_response` helper method
2022-08-08 12:23:09 +01:00
Yutaka Kamei
cfbea91a69
Support Proc type for stubbed request body (#1436)
Previously, the Faraday testing adapter compared the request body to the
stubbed body just by calling `#==` if the stubbed body is present.
Sometimes, I want to check the equality between request and stubbed body
in more advanced ways. For example, there is a case that I want to check
only the parts of the body are actually passed to Faraday instance like
this:

```ruby
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
  stub.post('/foo', '{"name:"YK","created_at":"ANY STRING IS OK"}') { [200, {}, ''] }
end
connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now))
stubs.verify_stubbed_calls
```

In this case, it's difficult to make tests always pass with
`"created_at"` because the value is dynamic. So, I came up with an idea
to pass a proc as a stubbed value and compare bodies, inside the proc:

```ruby
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
  check = -> (request_body) { JSON.parse(request_body).slice('name') == { 'name' => 'YK' } }
  stub.post('/foo', check) { [200, {}, ''] }
end
connection.post('/foo', JSON.dump(name: 'YK', created_at: Time.now))
stubs.verify_stubbed_calls
```

I believe this would be flexible but compatible with the previous behavior.
2022-07-28 10:03:13 +01:00
Konstantin S Kazarin
d420a12a57
Handle verify hostname ssl option (#1428) 2022-06-30 22:26:16 +01:00
Chris AtLee
a2b5f7f3a8
Allow application/x-www-form-url_encoded POST requests to use file objects as the request body (#1415) 2022-05-06 15:49:09 +01:00
Thomas Sanchez
f003443acc
Add indices when arrays are encoded (#1399) 2022-02-16 10:05:38 +00:00
Olle Jonsson
46f3b678f0 Refactor test
This avoids leaking the class definition.
2022-02-02 20:24:49 +01:00
Mattia Giuffrida
85dfdf824c Re-add register middleware w/ Symbol, String, Proc
Reintroduce the possibility to register middleware with symbols, strings or procs.

Fixes #1389
2022-02-02 20:24:49 +01:00
José Augusto
816d824bc1
Removing all sushi.com references and change to httpbingo.org (#1384)
Fixes #1164
2022-01-18 16:43:36 +00:00
Yuki Hirasawa
7f004913eb
Add default adapter options (#1382) 2022-01-15 14:32:39 +00:00
Mattia Giuffrida
cb47eca810 Remove multipart middleware and all its documentation and tests. 2022-01-03 09:40:52 +01:00