src/sse.bend checks
raw source on the hub · import ezmcp@0.2.0.0/src/sse.bend as Sse
ezmcp/src/sse: the data of a text/event-stream body, as an MCP client
reads a POST's reply when the server streams it
(basic/transports#sending-messages-to-the-server). Only data: fields
are read: an event's data is its data lines joined by newlines, and the
reply is the data of the last event that has any.
1 import
import Base
Types
type Sse source · line 10 · raw
Data
while reading: the current event's data so far (if it has any), and the data of the last event that ended
Sse@cur:Maybe<&2, String> -> @last:String -> Sse
Definitions
def unr.at source · line 14 · raw
@head:Char -> @rest:(@_:Unit -> String) -> @ends:Bool -> String
one char of a line: a \r that ends the line is dropped
def unr source · line 22 · raw
@text:String -> String
a line's text with one \r at its end dropped
def value source · line 31 · raw
@text:String -> String
a data field's value: the text after data:, less one space
def more source · line 39 · raw
@cur:Maybe<&2, String> -> @val:String -> Maybe<&2, String>
more data for the current event
def end source · line 47 · raw
@cur:Maybe<&2, String> -> @last:String -> Sse
the end of an event: its data, if any, is the latest
def line.data source · line 54 · raw
@cur:Maybe<&2, String> -> @last:String -> @+line:String -> @data:Bool -> Sse
def line.of source · line 66 · raw
@cur:Maybe<&2, String> -> @last:String -> @+line:String -> @blank:Bool -> Sse
def line source · line 79 · raw
@text:Sse -> @+line2:String -> Sse
one line of the stream
def lines source · line 85 · raw
@ls:List<&2, String> -> @text:Sse -> Sse
every line of the stream, in order
def fin source · line 93 · raw
@text:Sse -> String
the data the stream ends with: an unfinished event's, else the last one's
def last source · line 100 · raw
@body:String -> String
the data of the last event that has any; an event the stream cut off before its blank line still counts