Comments (20)
This depends on #72 and adding of Connection: Keep-Alive
support.
from http.
I had planned to add connection pools ala Net::HTTP::Persistent as well.
@sferik is this the sort of thing you're after?
https://github.com/drbrain/net-http-persistent
from http.
not "needed" atm but having something like net-http-persistent in http would give me one more reason to not depend on net/http if i needed to re-use the same socket.
from http.
@tarcieri Yes, I’m looking for something functionally similar to net-http-persistent
, however, I’m not such a fan of the interface, which reminds me of Net::HTTP. Have you thought about what the HTTP gem’s interface for persistent connections might look like?
from http.
imho something like HTTP.persistent("https://www.google.com").get("/foo").get("/bar")
could be nice.
from http.
@johnny5- I need to be able to make separate, unchained requests using the same connection object, so this would need to work:
connection = HTTP.persistent("https://www.google.com")
connection.get("/foo")
connection.get("/bar")
from http.
there's no reason it couldn't work with my example and yours.
from http.
i think it would mean response's would end up being stacked in connection
though and im not sure if that's good.
from http.
@johnny5- I just wanted to make sure it doesn’t require chaining the requests in a single statement.
from http.
supporting both might be odd, .get() could return a response that could proxy another .get() through to the same connection object, to implement chaining, but i think it's better if people more familiar with the code weigh in.
from http.
I'm totally opposed to idea of proxy objects. IMHO it's confusing magic. Why one would need to call get()
without getting response? I imagine API to be something like this:
client = HTTP.persisted # => HTTP::Client::Persisted
users = client.get("http://example.com/users.json")
groups = client.get("http://example.com/groups.json")
Persisted client will hold connection pool internally, so if one didn't flushed connection before making another one (above) it will create another connection. Once it will have more than one open (and fully flushed) connection to same host, it will close all superfluous ones. Also, if you will get different host - it will add another persisted connection to the pool. Persistence pool will be configurable (total size, per-host size, auto-flush upon next request).
Clarification on "if one didn't flushed connection before":
client = HTTP.persisted # => HTTP::Client::Persisted
# 0 open connections
puts client.get("http://example.com/users.json").to_s
puts client.get("http://example.com/users.json").to_s
# 1 open connection
resources = %w[users groups persmissions].map do |res|
client.get "http://example.com/#{res}.json"
end
# 3 open connections
resources.each { |r| r.to_s }
# 1 open connection
client.get("http://foobar.com/users.json").to_s
# 2 open connections
from http.
My ideal API would be transparent... that each HTTP::Client
would hold a pool of HTTP::Connection
objects per origin (perhaps with a toggle to use a pool or not). I'd define an origin as a tuple of:
[(:http|:https), hostname, port]
from http.
i totally agree a proxy on a response back to the original connection would be confusing as hell :)
from http.
Resolved via #184.
from http.
Hmmm…trying to move this issue into the v0.8.0 milestone but I’m getting an error. Maybe it’s related to the denial of service GitHub was facing earlier today? Anyway, this feature should be released in v0.8.0.
from http.
@tarcieri @ixti Are you able to change the milestone to v0.8.0?
from http.
@sferik GitHub is giving me an error when I try to do that o_O
from http.
@tarcieri Me too. I thought it might be a permissions thing. Let’s remember to try again when GitHub isn’t under attack. I’d guess they’ve temporarily disabled some non-critical services like reassigning milestones.
from http.
I found the workaround to assign milestones :D via issues index not from particular issue...
from http.
@ixti 👍
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
- Make HTTP::Feature work like rack middleware HOT 10
- 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.