Class: Wsv::Response::SseBody
- Inherits:
-
Object
- Object
- Wsv::Response::SseBody
- Defined in:
- lib/wsv/response/sse_body.rb
Overview
Body for Server-Sent Events responses. The producer block receives the client socket and writes SSE frames until it returns; the surrounding Connection then closes the TCP connection. Write errors after the peer disconnects (EPIPE, ECONNRESET, IOError) propagate out of #write_to and are swallowed by Connection#write, so producers do not need their own rescue. Producers should ‘io.flush` after each frame to defeat TCP buffering.
‘bytesize` returns 0 because SSE streams have no a-priori known size. AccessLog renders 0 bytes as `-` in Common Log Format.
Instance Method Summary collapse
- #bytesize ⇒ Object
-
#initialize(&producer) ⇒ SseBody
constructor
A new instance of SseBody.
- #to_s ⇒ Object
- #write_to(io) ⇒ Object
Constructor Details
#initialize(&producer) ⇒ SseBody
Returns a new instance of SseBody.
16 17 18 19 20 |
# File 'lib/wsv/response/sse_body.rb', line 16 def initialize(&producer) raise ArgumentError, "block required" unless producer @producer = producer end |
Instance Method Details
#bytesize ⇒ Object
26 27 28 |
# File 'lib/wsv/response/sse_body.rb', line 26 def bytesize 0 end |
#to_s ⇒ Object
22 23 24 |
# File 'lib/wsv/response/sse_body.rb', line 22 def to_s raise NotImplementedError, "SseBody has no static representation; use #write_to(io)" end |
#write_to(io) ⇒ Object
30 31 32 |
# File 'lib/wsv/response/sse_body.rb', line 30 def write_to(io) @producer.call(io) end |