format server-sent event (SSE), return the formatted string to send note: if data is a json array, it will be sent as multiple events, one per item
| 1345 | // format server-sent event (SSE), return the formatted string to send |
| 1346 | // note: if data is a json array, it will be sent as multiple events, one per item |
| 1347 | std::string format_oai_sse(const json & data) { |
| 1348 | std::ostringstream ss; |
| 1349 | auto send_single = [&ss](const json & data) { |
| 1350 | ss << "data: " << |
| 1351 | safe_json_to_str(data) << |
| 1352 | "\n\n"; // required by RFC 8895 - A message is terminated by a blank line (two line terminators in a row). |
| 1353 | }; |
| 1354 | |
| 1355 | if (data.is_array()) { |
| 1356 | for (const auto & item : data) { |
| 1357 | send_single(item); |
| 1358 | } |
| 1359 | } else { |
| 1360 | send_single(data); |
| 1361 | } |
| 1362 | |
| 1363 | return ss.str(); |
| 1364 | } |
| 1365 | |
| 1366 | std::string format_oai_resp_sse(const json & data) { |
| 1367 | std::ostringstream ss; |
no test coverage detected