Sha256: 61d685a2f2e53aeb5d3c1b9e2c77aa92fa3ab6a84f3268418394bc7754794c2f

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Angelo
  class Responder
    class Eventsource < Responder

      def initialize _headers = nil, &block
        headers _headers if _headers
        super &block
      end

      def request= request
        @params = nil
        @request = request
        handle_request
      end

      def handle_request
        begin
          if @response_handler
            @base.filter :before
            @body = catch(:halt) { @base.eventsource &@response_handler.bind(@base) }
            if HALT_STRUCT === @body
              raise RequestError.new 'unknown sse error' unless @body.body == :sse
            end

            # TODO any real reason not to run afters with SSE?
            # @base.filter :after

            respond
          else
            raise NotImplementedError
          end
        rescue IOError => ioe
          warn "#{ioe.class} - #{ioe.message}"
        rescue RequestError => re
          handle_error re, re.type
        rescue => e
          handle_error e
        end
      end

      def respond
        Angelo.log @connection, @request, nil, :ok
        @request.respond 200, headers, nil
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
angelo-0.1.24 lib/angelo/responder/eventsource.rb