Class: RubstApi::EventSourceResponse
- Inherits:
-
StreamingResponse
- Object
- Response
- StreamingResponse
- RubstApi::EventSourceResponse
- Defined in:
- lib/rubst_api/sse.rb
Instance Attribute Summary
Attributes inherited from Response
#body, #headers, #media_type, #status_code
Instance Method Summary collapse
-
#initialize(content, ping: 15, **options) ⇒ EventSourceResponse
constructor
A new instance of EventSourceResponse.
Methods inherited from StreamingResponse
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, **) 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" }, **) end |