Skip to content

Commit

Permalink
Don't wrap request bodies if they are already Readables
Browse files Browse the repository at this point in the history
We don't need to wrap request bodies if they already conform to the `::Protocol::HTTP::Body::Readable` interface. This way developers can use other kinds of `Readable`s directly when making calls with `Faraday`.
  • Loading branch information
jakeonfire authored Jul 13, 2024
1 parent df3b831 commit 99a2338
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/async/http/faraday/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def call(env)
if body = env.body
# We need to wrap the body in a Readable object so that it can be read in chunks:
# Faraday's body only responds to `#read`.
if body.respond_to?(:read)
if body.is_a?(::Protocol::HTTP::Body::Readable)
# Good to go
elsif body.respond_to?(:read)
body = BodyReadWrapper.new(body)
else
body = ::Protocol::HTTP::Body::Buffered.wrap(body)
Expand Down

0 comments on commit 99a2338

Please sign in to comment.