From 516ce25876a10f4f7d77f73637cbc496f6dbd69e Mon Sep 17 00:00:00 2001 From: Matt Poegel Date: Thu, 14 Sep 2023 01:55:56 +0000 Subject: [PATCH] fix server event new line bug --- http/fwoop_httpserver.cpp | 2 +- http/fwoop_httpserverevent.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/http/fwoop_httpserver.cpp b/http/fwoop_httpserver.cpp index 41c753f..5baf965 100644 --- a/http/fwoop_httpserver.cpp +++ b/http/fwoop_httpserver.cpp @@ -291,7 +291,7 @@ int HttpServer::parsePayloadBody(uint8_t *buffer, unsigned int bufferSize, unsig { bytesParsed = 0; std::string payload((char *)buffer, bufferSize); - unsigned int end = payload.rfind("\r\n\r\n"); + auto end = payload.rfind("\r\n\r\n"); if (end == std::string::npos) { bytesParsed = bufferSize; } else { diff --git a/http/fwoop_httpserverevent.cpp b/http/fwoop_httpserverevent.cpp index 9cbc2bf..1a9dcfd 100644 --- a/http/fwoop_httpserverevent.cpp +++ b/http/fwoop_httpserverevent.cpp @@ -28,7 +28,7 @@ bool HttpServerEvent::pushEvent(const std::string &event, const std::string &dat static const unsigned int EVENT_PREFIX_LEN = strlen(EVENT_PREFIX); static const unsigned int DATA_PREFIX_LEN = strlen(DATA_PREFIX); - const unsigned int outLen = EVENT_PREFIX_LEN + DATA_PREFIX_LEN + event.length() + data.length() + 2; + const unsigned int outLen = EVENT_PREFIX_LEN + DATA_PREFIX_LEN + event.length() + data.length() + 3; uint8_t *out = new uint8_t[outLen]; memset(out, 0, outLen); unsigned int offset = 0; @@ -42,6 +42,7 @@ bool HttpServerEvent::pushEvent(const std::string &event, const std::string &dat memcpy(out + offset, data.data(), data.length()); offset += data.length(); out[offset++] = '\n'; + out[offset++] = '\n'; int rc = SocketIO::write(d_fd, out, outLen); delete[] out;