Skip to content

ServerSentEvent type does not match the WhatWG specification WRT comments #379

@arturaz

Description

@arturaz

The model defined in

case class ServerSentEvent(
data: Option[String] = None,
eventType: Option[String] = None,
id: Option[String] = None,
retry: Option[Int] = None
) {
override def toString: String = {
val _data = data.map(_.split("\n")).map(_.map(line => Some(s"data: $line"))).getOrElse(Array.empty[Option[String]])
val _event = eventType.map(event => s"event: $event")
val _id = id.map(id => s"id: $id")
val _retry = retry.map(retryCount => s"retry: $retryCount")
(_data :+ _event :+ _id :+ _retry).flatten.mkString("\n")
}
}
does not match the specification at https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation

Specifically, this part:

If the line starts with a U+003A COLON character (:)

Ignore the line.

Therefore there is currently no way to send or receive "comment" messages, which are useful to perform keep-alives.

One could argue that you can just send event: keep-alive here, to which I agree, but just noticed this discrepancy and wondered whether we should add a way to send out these comment messages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions