fetch-event-source icon indicating copy to clipboard operation
fetch-event-source copied to clipboard

onmessage called for comment lines

Open brandonbloom opened this issue 3 years ago • 1 comments

The onmessage callback is called with an empty message if the server sends \n:\n. The spec says that servers can choose to send : as a form of keep-alive message every 15 seconds or so.

The bug is here: https://github.com/Azure/fetch-event-source/blob/45ac3cfffd30b05b79fbf95c21e67d4ef59aa56a/src/parse.ts#L129-L133

The comment on the last line of that reads "exclude comments and lines with no values", but onMessage?.(message) is called unconditionally on a blank line. Instead, empty messages should not be emitted.

Luckily, for my use case, I control the server, so as a workaround, I can remove the extra trailing \n from the keep-alive message.

brandonbloom avatar Mar 09 '22 17:03 brandonbloom