You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
URL-encoded bodies are not readable - request errors during processing #36
it seems setting the body to a hash for url_encoded requests results in a String body in the async faraday adapter where it is expecting a Readable?
49.64s warn: Async::Task: Writing #<Async::HTTP::Faraday::BodyWrapper:0x0000ffffa59bc440> to #<Async::HTTP::Protocol::HTTP2::Response::Stream:0x0000ffffa758a1e0>. [oid=0x23a0] [ec=0x23b4] [pid=149] [2024-02-07 20:54:59 +0000]
| Task may have ended with unhandled exception.
| NoMethodError: undefined method `read' for "foo=42":String
| → /usr/local/bundle/gems/async-http-faraday-0.13.0/lib/async/http/faraday/adapter.rb:34 in `read'
| /usr/local/bundle/gems/async-http-0.63.0/lib/async/http/protocol/http2/output.rb:83 in `passthrough'
| /usr/local/bundle/gems/async-2.8.1/lib/async/task.rb:161 in `block in run'
| /usr/local/bundle/gems/async-2.8.1/lib/async/task.rb:331 in `block in schedule'
I'm surprised this never happened before because to my knowledge it's fairly common for Faraday to pass a string as the request body for post/put/patch methods 🤔
Is there documentation about what valid body can be and what to do with it
Not really, because what the adapter expects can vary wildly. As I said though, to my knowledge, String is almost always what is given to the adapter (after middleware takes whatever the input is, like a Hash and turns that into a string).
mmmh it seems like Net::HTTP supports #read as well, but you need to pass it explicitly as body_stream.
To be fair, Faraday have just recently added first-class support for RESPONSE streaming, this looks more like we want to support request body streaming. Might be a good addition to the API.
Adapters like async-http will support it transparently, while others like net-http would require some extra code
For sure it seems needed for multipart post - because that is a rich object which responds to #read so I'm not sure how other clients are handling it (it was simply assigned to #body).
Activity
ioquatix commentedon Feb 7, 2024
@iMacTia is there documentation about what valid
bodycan be and what to do with it i.e. how to get a consistent readable interface?jakeonfire commentedon Feb 7, 2024
work-around for now:
ioquatix commentedon Feb 7, 2024
I think I found the solution, I'll try to make a release within a few hours including the fix.
jakeonfire commentedon Feb 8, 2024
also seeing this with e.g.
fwiw. almost certainly has the same fix, though.
ioquatix commentedon Feb 8, 2024
Do you mind trying out
v0.13.1which was just released. It should fix the issue.jakeonfire commentedon Feb 8, 2024
v0.13.1fixes the issue 🥳 thanks!iMacTia commentedon Feb 8, 2024
Thank you for the quick fix @ioquatix 🙌
I'm surprised this never happened before because to my knowledge it's fairly common for Faraday to pass a string as the request body for post/put/patch methods 🤔
ioquatix commentedon Feb 8, 2024
It seems like it's at least either:
Stringinstance, or#read.iMacTia commentedon Feb 8, 2024
mmmh it seems like
Net::HTTPsupports#readas well, but you need to pass it explicitly as body_stream.To be fair, Faraday have just recently added first-class support for RESPONSE streaming, this looks more like we want to support request body streaming. Might be a good addition to the API.
Adapters like
async-httpwill support it transparently, while others likenet-httpwould require some extra codeioquatix commentedon Feb 8, 2024
For sure it seems needed for multipart post - because that is a rich object which responds to
#readso I'm not sure how other clients are handling it (it was simply assigned to#body).iMacTia commentedon Feb 8, 2024
Actually yes, Net::HTTP does support streams, but you also have to set
Content-Lengthin that case or you'll get the following error back:And this is exactly what
faraday-multipartdoes: https://github.com/lostisland/faraday-multipart/blob/main/lib/faraday/multipart/middleware.rb#L63So yeah, it seems like adapters should support both. Documentation should definitely point this out more explicitly
iMacTia commentedon Feb 8, 2024
Opened lostisland/faraday#1554, thank you so much for the discussion 🙌 !