Sha256: dc9da369d32136a079b90f039474670c6348f16c506dd580a6f5a5bfd20a9fc6

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

module HTTPI
  module Adapter

    # = HTTPI::Adapter::NetHTTPPersistent
    #
    # Adapter for the Net::HTTP::Persistent client.
    # http://docs.seattlerb.org/net-http-persistent/Net/HTTP/Persistent.html
    class NetHTTPPersistent < NetHTTP

      register :net_http_persistent, :deps => %w(net/http/persistent)

      private

      def create_client
        Net::HTTP::Persistent.new thread_key
      end

      def perform(http, http_request, &on_body)
        http.request @request.url, http_request, &on_body
      end

      def do_request(type, &requester)
        setup
        response = requester.call @client, request_client(type)
        respond_with(response)
      end

      def setup_client
        if @request.auth.ntlm?
          raise NotSupportedError, "Net::HTTP-Persistent does not support NTLM authentication"
        end

        @client.open_timeout = @request.open_timeout if @request.open_timeout
        @client.read_timeout = @request.read_timeout if @request.read_timeout
      end

      def thread_key
        @request.url.host.split(/\W/).reject{|p|p == ""}.join('-')
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
httpi-2.4.3 lib/httpi/adapter/net_http_persistent.rb
httpi-2.4.2 lib/httpi/adapter/net_http_persistent.rb
httpi-2.4.1 lib/httpi/adapter/net_http_persistent.rb
httpi-2.4.0 lib/httpi/adapter/net_http_persistent.rb
httpi-2.3.0 lib/httpi/adapter/net_http_persistent.rb
httpi-2.1.1 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.7 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.6 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.5 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.4 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.3 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.1 lib/httpi/adapter/net_http_persistent.rb
httpi-2.2.0 lib/httpi/adapter/net_http_persistent.rb
httpi-2.1.0 lib/httpi/adapter/net_http_persistent.rb