Skip to content

Commit 38fc1aa

Browse files
committed
split out non-HTTP server parts
1 parent 28baac9 commit 38fc1aa

File tree

4 files changed

+4062
-4060
lines changed

4 files changed

+4062
-4060
lines changed

tools/server/http-utils.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
// increase max payload length to allow use of larger context size
3+
#define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 1048576
4+
// increase backlog size to avoid connection resets for >> 1 slots
5+
#define CPPHTTPLIB_LISTEN_BACKLOG 512
6+
// disable Nagle's algorithm
7+
#define CPPHTTPLIB_TCP_NODELAY true
8+
#include <cpp-httplib/httplib.h>
9+
10+
static bool server_sent_event(httplib::DataSink & sink, const json & data) {
11+
const std::string str =
12+
"data: " +
13+
data.dump(-1, ' ', false, json::error_handler_t::replace) +
14+
"\n\n"; // required by RFC 8895 - A message is terminated by a blank line (two line terminators in a row).
15+
16+
LOG_DBG("data stream, to_send: %s", str.c_str());
17+
18+
return sink.write(str.c_str(), str.size());
19+
}

0 commit comments

Comments
 (0)