Sha256: 0642418c1444780654f5d5a13fe49822c64184408a517d2c44c58fdbd724303d

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

module Angelo
  class Responder
    class Eventsource < Responder

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

      def handle_request
        begin
          if @response_handler
            @base.before if @base.respond_to? :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.after if @base.respond_to? :after

            respond
          else
            raise NotImplementedError
          end
        rescue IOError => ioe
          warn "#{ioe.class} - #{ioe.message}"
          close_websocket
        rescue => e
          error e.message
          ::STDERR.puts e.backtrace
          begin
            @connection.close
          rescue Reel::StateError => rcse
            close_websocket
          end
        end
      end

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

    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
angelo-0.1.22 lib/angelo/responder/eventsource.rb
angelo-0.1.21 lib/angelo/responder/eventsource.rb
angelo-0.1.19 lib/angelo/responder/eventsource.rb
angelo-0.1.18 lib/angelo/responder/eventsource.rb
angelo-0.1.17 lib/angelo/responder/eventsource.rb
angelo-0.1.16 lib/angelo/responder/eventsource.rb
angelo-0.1.15 lib/angelo/responder/eventsource.rb