Class: Firehose::Rack::Consumer::HttpLongPoll::Handler

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/firehose/rack/consumer/http_long_poll.rb

Direct Known Subclasses

DefaultHandler, MultiplexingHandler

Instance Method Summary collapse

Methods included from Helpers

#response

Constructor Details

#initialize(timeout = TIMEOUT) {|_self| ... } ⇒ Handler

Returns a new instance of Handler.

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
# File 'lib/firehose/rack/consumer/http_long_poll.rb', line 29

def initialize(timeout=TIMEOUT)
  @timeout = timeout
  yield self if block_given?
end

Instance Method Details

#call(env) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/firehose/rack/consumer/http_long_poll.rb', line 34

def call(env)
  request = request(env)
  method  = request.request_method

  case method
  # GET is how clients subscribe to the queue. When a messages comes in, we flush out a response,
  # close down the requeust, and the client then reconnects.
  when "GET"
    handle_request(request, env)
    return ASYNC_RESPONSE
  # we use post messages for http long poll multiplexing
  when "POST"
    if Consumer.multiplexing_request?(env)
      handle_request(request, env)
      return ASYNC_RESPONSE
    end
  end

  Firehose.logger.debug "HTTP #{method} not supported"
  response(405, "#{method} not supported.", "Allow" => "GET")
end