Merge pull request #181 from Tarik2142/sse_0xa_fix

SSE 0xa fix
This commit is contained in:
Mathieu Carbou
2024-12-19 14:28:58 +01:00
committed by GitHub

View File

@@ -23,6 +23,8 @@
#endif #endif
#include "AsyncEventSource.h" #include "AsyncEventSource.h"
#define ASYNC_SSE_NEW_LINE_CHAR (char)0xa
using namespace asyncsrv; using namespace asyncsrv;
static String generateEventMessage(const char* message, const char* event, uint32_t id, uint32_t reconnect) { static String generateEventMessage(const char* message, const char* event, uint32_t id, uint32_t reconnect) {
@@ -41,19 +43,19 @@ static String generateEventMessage(const char* message, const char* event, uint3
if (reconnect) { if (reconnect) {
str += T_retry_; str += T_retry_;
str += reconnect; str += reconnect;
str += (char)0xa; // '\n' str += ASYNC_SSE_NEW_LINE_CHAR; // '\n'
} }
if (id) { if (id) {
str += T_id__; str += T_id__;
str += id; str += id;
str += (char)0xa; // '\n' str += ASYNC_SSE_NEW_LINE_CHAR; // '\n'
} }
if (event != NULL) { if (event != NULL) {
str += T_event_; str += T_event_;
str += event; str += event;
str += (char)0xa; // '\n' str += ASYNC_SSE_NEW_LINE_CHAR; // '\n'
} }
if (!message) if (!message)
@@ -95,13 +97,13 @@ static String generateEventMessage(const char* message, const char* event, uint3
str += T_data_; str += T_data_;
str.concat(lineStart, lineEnd - lineStart); str.concat(lineStart, lineEnd - lineStart);
str += 0xa; // \n str += ASYNC_SSE_NEW_LINE_CHAR; // \n
lineStart = nextLine; lineStart = nextLine;
} while (lineStart < ((char*)message + messageLen)); } while (lineStart < ((char*)message + messageLen));
// append another \n to terminate message // append another \n to terminate message
str += 0xa; // '\n' str += ASYNC_SSE_NEW_LINE_CHAR; // '\n'
return str; return str;
} }