From 99a233863a1a56b802463bf910dc13b67fa2dae9 Mon Sep 17 00:00:00 2001 From: Jacob Frautschi Date: Fri, 12 Jul 2024 17:17:31 -0700 Subject: [PATCH] Don't wrap request bodies if they are already Readables 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`. --- lib/async/http/faraday/adapter.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/async/http/faraday/adapter.rb b/lib/async/http/faraday/adapter.rb index 06f017f..ebae7dd 100644 --- a/lib/async/http/faraday/adapter.rb +++ b/lib/async/http/faraday/adapter.rb @@ -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)