Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Persistent http connections using a connection pool
Ruby
branch: master
Failed to load latest commit information.
lib Put default_path, host and port getters back into persistent_http for…
test Separate out connection and pool logic
.gitignore 1.0.6
.travis.yml Allow rbx failures - it times out
Gemfile Don't need jruby-openssl with jruby 1.7
History.md Put default_path, host and port getters back into persistent_http for…
LICENSE Allow options to request to allow changing of read_timeout and possib…
README.rdoc Added pool_timeout option
Rakefile Allow options to request to allow changing of read_timeout and possib…
persistent_http.gemspec

README.rdoc

persistent_http

DESCRIPTION:

Persistent connections using Net::HTTP with a connection pool.

This is based on Eric Holder's Net::HTTP::Persistent libary but uses a connection pool of Net::HTTP objects instead of a connection per thread. C/T is fine if you're only using your http threads to make connections but if you use them in child threads then I suspect you will have a thread memory leak. Also, you will generally get less connection resets if the most recently used connection is always returned.

FEATURES/PROBLEMS:

  • Supports SSL

  • Thread-safe

  • Pure ruby

  • Timeout-less speed boost for 1.8 (by Aaron Patterson)

INSTALL:

gem install persistent_http

EXAMPLE USAGE:

require 'persistent_http'

class MyHTTPClient
  @@persistent_http = PersistentHTTP.new(
    :name         => 'MyHTTPClient',
    :logger       => Rails.logger,
    :pool_size    => 10,
    :pool_timeout => 5,
    :warn_timeout => 0.25,
    :force_retry  => true,
    :url          => 'https://www.example.com/echo/foo'  # equivalent to :use_ssl => true, :host => 'www.example.com', :default_path => '/echo/foo'
  )

  def send_get_message
    response = @@persistent_http.request
    ... Handle response as you would a normal Net::HTTPResponse ...
  end

  def send_post_message
    request = Net::HTTP::Post.new('/perform_service')
    ... Modify request as needed ...
    response = @@persistent_http.request(request)
    ... Handle response as you would a normal Net::HTTPResponse ...
  end
end

Copyright

Copyright © 2010-2012 Eric Hodel, Aaron Patterson, Brad Pardee. See LICENSE for details.

Something went wrong with that request. Please try again.