Class: RubstApi::EventSourceResponse

Inherits:
StreamingResponse show all
Defined in:
lib/rubst_api/sse.rb

Instance Attribute Summary

Attributes inherited from Response

#body, #headers, #media_type, #status_code

Instance Method Summary collapse

Methods inherited from StreamingResponse

#finish

Methods inherited from Response

#delete_cookie, #finish, #render, #set_cookie

Constructor Details

#initialize(content, ping: 15, **options) ⇒ EventSourceResponse

Returns a new instance of EventSourceResponse.



18
19
20
21
22
23
24
25
26
# File 'lib/rubst_api/sse.rb', line 18

def initialize(content, ping: 15, **options)
  stream = Enumerator.new do |output|
    content.each do |event|
      event = ServerSentEvent.new(event, nil, nil, nil, nil) unless event.is_a?(ServerSentEvent)
      output << event.encode
    end
  end
  super(stream, media_type: "text/event-stream", headers: { "cache-control" => "no-cache" }, **options)
end