Sha256: 9f894c9843156027f92d41156b24e45c1e6de51e0d4425a79c4f8a39ef9bdaf1

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

module EventMachine
  class HttpRequest
    @middleware = []

    def self.new(uri, options={})
      begin
        req = HttpOptions.new(uri, options)

        EventMachine.connect(req.host, req.port, HttpConnection) do |c|
          c.opts = req

          c.pending_connect_timeout = req.options[:connect_timeout]
          c.comm_inactivity_timeout = req.options[:inactivity_timeout]
        end

      rescue EventMachine::ConnectionError => e
        #
        # Currently, this can only fire on initial connection setup
        # since #connect is a synchronous method. Hence, rescue the
        # exception, and return a failed deferred which will immediately
        # fail any client request.
        #
        # Once there is async-DNS, then we'll iterate over the outstanding
        # client requests and fail them in order.
        #
        # Net outcome: failed connection will invoke the same ConnectionError
        # message on the connection deferred, and on the client deferred.
        #
        conn = EventMachine::FailedConnection.new(req)
        conn.error = e.message
        conn.fail
        conn
      end
    end

    def self.use(klass)
      @middleware << klass
    end

    def self.middleware
      @middleware
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
em-http-request-1.0.0.beta.3 lib/em-http/request.rb
em-http-request-1.0.0.beta.2 lib/em-http/request.rb
em-http-request-1.0.0.beta.1 lib/em-http/request.rb