Coder Social home page Coder Social logo

Connection sharing about http HOT 20 CLOSED

httprb avatar httprb commented on June 19, 2024
Connection sharing

from http.

Comments (20)

ixti avatar ixti commented on June 19, 2024

This depends on #72 and adding of Connection: Keep-Alive support.

from http.

tarcieri avatar tarcieri commented on June 19, 2024

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.

 avatar commented on June 19, 2024

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.

sferik avatar sferik commented on June 19, 2024

@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.

 avatar commented on June 19, 2024

imho something like HTTP.persistent("https://www.google.com").get("/foo").get("/bar") could be nice.

from http.

sferik avatar sferik commented on June 19, 2024

@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.

 avatar commented on June 19, 2024

there's no reason it couldn't work with my example and yours.

from http.

 avatar commented on June 19, 2024

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.

sferik avatar sferik commented on June 19, 2024

@johnny5- I just wanted to make sure it doesn’t require chaining the requests in a single statement.

from http.

 avatar commented on June 19, 2024

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.

ixti avatar ixti commented on June 19, 2024

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.

tarcieri avatar tarcieri commented on June 19, 2024

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.

 avatar commented on June 19, 2024

i totally agree a proxy on a response back to the original connection would be confusing as hell :)

from http.

sferik avatar sferik commented on June 19, 2024

Resolved via #184.

from http.

sferik avatar sferik commented on June 19, 2024

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.

sferik avatar sferik commented on June 19, 2024

@tarcieri @ixti Are you able to change the milestone to v0.8.0?

from http.

tarcieri avatar tarcieri commented on June 19, 2024

@sferik GitHub is giving me an error when I try to do that o_O

from http.

sferik avatar sferik commented on June 19, 2024

@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.

ixti avatar ixti commented on June 19, 2024

I found the workaround to assign milestones :D via issues index not from particular issue...

from http.

sferik avatar sferik commented on June 19, 2024

@ixti 👍

from http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.