Comments (10)
This was a deliberate design decision.
See the many, many years of previous discussion. Here's a summary: #478 (comment)
This was the resolution: #482 #499
from http.
This was a deliberate design decision.
See the many, many years of previous discussion. Here's a summary: #478 (comment)
I respect your decision. But is it possible to change the execution orders?
Just change client.rb#L84:
# res = options.features.inject(res) do |response, (_name, feature)|
res = options.features.to_a.reverse.to_h.inject(res) do |response, (_name, feature)|
feature.wrap_response(response)
end
Suppose we have three features, logging
, auto_deflate
, auto_inflate
. If i want log the uncompressed request/response body, only [:auto_inflate, :logging, :auto_deflate]
make sense. It's a little strange.
[:logging, :auto_deflate, :auto_inflate] # response in log is compressed
[:logging, :auto_inflate, :auto_deflate] # response in log is compressed
# 1. logging#wrap_request
# 2. auto_deflate#wrap_request
# 3. _REAL_HTTP_REQUEST_
# 4. logging#wrap_response
# 5. auto_inflate#wrap_response
[:auto_deflate, :auto_inflate, :logging] # request in log is compressed
[:auto_inflate, :auto_deflate, :logging] # request in log is compressed
# 1. auto_deflate#wrap_request
# 2. logging#wrap_request
# 3. _REAL_HTTP_REQUEST_
# 4. auto_inflate#wrap_response
# 5. logging#wrap_response
[:auto_deflate, :logging, :auto_inflate] # request/response in log is compressed
# 1. auto_deflate#wrap_request
# 2. logging#wrap_request
# 3. _REAL_HTTP_REQUEST_
# 4. logging#wrap_response
# 5. auto_inflate#wrap_response
from http.
If you're asking if it would be okay for features to be applied to responses to handled in the reverse order from the requests, that makes sense to me, though I would worry somewhat about it breaking existing code if it were done outside of a breaking release.
from http.
If you're asking if it would be okay for features to be applied to responses to handled in the reverse order from the requests, that makes sense to me, though I would worry somewhat about it breaking existing code if it were done outside of a breaking release.
Updated, plz see #766
from http.
Oh. I really like that you've started working on session gem. I was thinking about it for a very long time (and due to some personal issues never had time for that). I was thinkign about a bit different API for that though:
session = HTTP::Session.new(...)
session.with do |http|
http.headers(...).get(...)
end
The idea I had was to use connection pool, so that connection would be kept alive just like in browsers.
from http.
On the features order of execution — I think we should provide them with the expected order of the execution. In rack middlewares world, you can tell where to inject the middleware. We should come with similar solution, so that features will be executed in predictable order.
HTTP.use(:feature_1).use(:feature_2, before: :feature_1)
Or using "weights" on features themselves (this will be less predicatble though):
class AutoInflateFeature < Feature
weight 9000
...
end
class LoggingFeature < Feature
weight 0
end
Weight-based one will allow us to change use
API as well to allow override default weight:
HTTP.use(:logging, weight: 100)
NB: I'm not proposing going russian-doll middleware pattern. But to provide a way to control feature execution order.
from http.
However that ordering is determined, I think reversing that ordering for processing responses as in #766 better maps to the sort of LIFO/FILO ordering you'd get with middlewares, where the ordering for middlewares lives in the call stack
from http.
However that ordering is determined, I think reversing that ordering for processing responses as in #766 better maps to the sort of LIFO/FILO ordering you'd get with middlewares, where the ordering for middlewares lives in the call stack
I totally agree with that.
from http.
Oh. I really like that you've started working on session gem. I was thinking about it for a very long time (and due to some personal issues never had time for that). I was thinkign about a bit different API for that though:
session = HTTP::Session.new(...) session.with do |http| http.headers(...).get(...) endThe idea I had was to use connection pool, so that connection would be kept alive just like in browsers.
HTTP::Session
has a similar api interface to HTTP::Client
, such as timeout
/follow
/via
, except persistent
.
IMO, we can turn on the keep-alive feature for all requests when using session, like python-requests
. e.g.
http = HTTP::Session.new(..., persistent: true).timeout(8).freeze
http.get('https://example.com/abc') # -> make a persistent connection
http.get('https://example.com/def') # -> automatically reuse the connection
But in order to work with multiple threads, a bit more work is required. So it not implement yet.
from http.
On the features order of execution — I think we should provide them with the expected order of the execution. In rack middlewares world, you can tell where to inject the middleware. We should come with similar solution, so that features will be executed in predictable order.
HTTP.use(:feature_1).use(:feature_2, before: :feature_1)Or using "weights" on features themselves (this will be less predicatble though):
class AutoInflateFeature < Feature weight 9000 ... end class LoggingFeature < Feature weight 0 endWeight-based one will allow us to change
use
API as well to allow override default weight:HTTP.use(:logging, weight: 100)NB: I'm not proposing going russian-doll middleware pattern. But to provide a way to control feature execution order.
We may still need a way to adjust execution orders, e.g.
http = HTTP.use(:feature_1)
http.get('https://example.com/abc')
http.get('https://example.com/def', features: { feature_2: {} }) # only want to use this feature in this request, and want it to run before :feature_1
But currently it may not necessary.
from http.
Related Issues (20)
- Requests to an IPv6 address result in: HTTP::ConnectionError (failed to connect: getaddrinfo: Name or service not known) HOT 13
- Incorrect method documentation? HOT 2
- feature request: happy eyeballs
- Can we update to llhttp-ffi 0.5.0 HOT 2
- access ssl certificate details? HOT 4
- Issues running it on Mac Intel (12.6) HOT 3
- SSLERROR occurred when running http method in the executable file: certificate verify failed. HOT 1
- 403 and 404 responses for valid URLs HOT 7
- raise error when invalid hash is passed to timeout HOT 1
- Are you open to include rspec_matchers? HOT 18
- File descriptor / socket leak when timeout occurs during initialization
- How to query the remote server address? HOT 1
- Remove auth header after following a redirect to a different origin
- Support HTTP headers streaming HOT 2
- Timeout redesign for 6.x HOT 4
- Fix Base64 dependency warning HOT 4
- Version 5.x bump? HOT 3
- project level timeout HOT 2
- `HTTP::Response::Body#each` and `BUFFER_SIZE`
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 http.