Skip to content

Commit

Permalink
fix server event new line bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoegel committed Sep 14, 2023
1 parent a3769e2 commit 516ce25
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion http/fwoop_httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion http/fwoop_httpserverevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 516ce25

Please sign in to comment.