Ignore an SSE id that cannot be sent as Last-Event-ID

SSEClient stored any id it received, but the client rejects a request
whose header value is invalid. An id with a NUL, a control character or
surrounding whitespace therefore made every reconnect fail with
Error::InvalidHeaders before reaching the server, and the id could
never be replaced.

Accept an id only if it is a valid header value, so that the previous
id stays in effect. The SSE spec asks for this for NUL only; the rest
follows from what this client can send.
This commit is contained in:
yhirose committed 2026-10-11 23:05:38 -04:00
1 parent fee592c2c2
commit 5189edc52e
2 files changed
+28 -3

No files matched your search

+6 -3
View File
@@ -4918,9 +4918,12 @@ inline bool SSEClient::parse_sse_line(const std::string &line, SSEMessage &msg,
msg.data += value;
has_data = true;
} else if (field == "id") {
// Empty id is valid (clears the last event ID)
msg.id = value;
has_id = true;
// An id that cannot be sent back as Last-Event-ID is ignored. Empty id is
// valid (clears the last event ID)
if (detail::fields::is_field_value(value)) {
msg.id = value;
has_id = true;
}
} else if (field == "retry") {
// Parse retry interval in milliseconds
// Per the SSE spec, a value that is not all ASCII digits is ignored.