Comments (7)
Note: The source code for the relevant middleware lives in the faraday_middleware gem: https://github.com/pengwynn/faraday_middleware/tree/master/lib/faraday/response
from faraday.
This is not breakage, it's something I actually fixed in Faraday. From the README:
The order in which middleware is stacked is important. Like with Rack, the first middleware on the list wraps all others, while the last middleware is the innermost one, so that's usually the adapter.
Before my refactoring, Faraday respected this to some extent, but the order in which on_complete
handlers fired was a total mess and very inconsistent. Now there's only one rule: request middleware fires in order in which they were added, response middleware fires in the reverse order. Adapters come last in the bottom. This is the standard Rack way.
Your stack should look like:
Faraday.new(options) do |builder|
builder.request :multipart
builder.request :url_encoded
builder.use Faraday::Request::OAuth, authentication if authenticated?
builder.use Faraday::Response::Mashify unless raw
unless raw
case format.to_s.downcase
when 'json'
builder.use Faraday::Response::ParseJson
when 'xml'
builder.use Faraday::Response::ParseXml
end
end
builder.use Faraday::Response::RaiseHttp4xx
builder.use Faraday::Response::RaiseHttp5xx
builder.adapter(adapter)
end
Now XML/JSON will first get parsed, then mashified.
One more note: the bundled Multipart middleware is a little different than the one you removed. The bundled one still doesn't handle "File" instances.
from faraday.
Thanks for explaining. The ordering was confusing me.
Is there a reason why the built-in Multipart
middleware doesn't handle "File" instances? Would it make sense to replace the one in faraday
with the one in the twitter
gem, which handles files correctly?
Or maybe I should add MultipartWithFile
middleware to the faraday_middleware
gem?
from faraday.
I just ran into another issue where env[:http_headers]
used to return {}
when it was blank, but now it returns nil
. Was this intentional?
from faraday.
I'd welcome that you contribute File handling together with mime-type guessing based on filename.
As for http_headers
: you must have confused that with request_headers
or response_headers
.
from faraday.
Yes, I meant response_headers
. Was that an intention move to change the default to nil
when they're empty? I needed to make this change to make it work: jnunemaker/twitter@97644a9#diff-1
from faraday.
That's a bug. Is this with the test adapter? Please file an issue.
Luckily, in real world response headers are never empty.
from faraday.
Related Issues (20)
- Forward env to Authorization#header_from ? HOT 4
- Configurable JSON backend
- Document middlewares order (priority) HOT 8
- Faraday unknown request issue HOT 2
- undefined method `pretty_inspect` in 2.7.0
- I am having trouble getting a JWT from a POST request. HOT 3
- Faraday 2.7.1 causes following warning: "warning: method redefined; discarding old error" HOT 1
- Difference between `timeout` and `open_timeout` HOT 4
- Typo in Adapters documentation
- URL not included in response hash HOT 2
- Support for Ubuntu 22.04, using OpenSSL 3.0.2 (i.e. Heroku 22) HOT 1
- ArgumentError due to missing ruby2_keywords on Ruby 3.2.0 HOT 4
- 2.7.3 breaks compatibility with Addressable as URI parser HOT 5
- Impossible to make request with same-name multi-value headers HOT 6
- Remove `default_uri_parser` config HOT 3
- Header matching inconsistency with strict_mode and verify_stubbed_calls HOT 4
- Fix YARD doc for Options HOT 1
- Faraday::ConnectionFailed if proxy: "" is passed on Ruby 3.2.1
- Block private ips (allow_private_ips) HOT 3
- Multiple "already initialized constant" warnings HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from faraday.