Support responses with no specified length

This commit is contained in:
Alex Hultman
2018-09-20 23:14:50 +02:00
parent 932b0b8944
commit 178dae70c2
3 changed files with 69 additions and 32 deletions
+12 -3
View File
@@ -37,7 +37,7 @@ std::string_view getFile(std::string_view file) {
#include <set>
std::set<uWS::HttpResponse<true> *> delayedResponses;
std::set<uWS::HttpResponse<false> *> delayedResponses;
int main(int argc, char **argv) {
@@ -56,13 +56,22 @@ int main(int argc, char **argv) {
}, 1000, 1000);
uWS::SSLApp({
uWS::/*SSL*/App(/*{
.key_file_name = "/home/alexhultman/uWebSockets/misc/ssl/key.pem",
.cert_file_name = "/home/alexhultman/uWebSockets/misc/ssl/cert.pem",
.dh_params_file_name = "/home/alexhultman/dhparams.pem",
.passphrase = "1234"
}).get("/", [](auto *res, auto *req) {
}*/).get("/", [](auto *res, auto *req) {
res->writeStatus(uWS::HTTP_200_OK)->write("Hello world!");
}).get("/endless", [](auto *res, auto *req) {
/* This route doesn't specify any length and only returns 1 char per chunk */
res->write([](int offset) {
std::string_view data("<html><body><h1>Hello, world</h1></body></html>");
if (offset < data.length()) {
return std::make_pair<bool, std::string_view>(offset < data.length() - 1, data.substr(offset, 1));
}
return uWS::HTTP_STREAM_FIN;
});
}).get("/delayed", [](auto *res, auto *req) {
/* This route streams back chunks of data in delayed fashion */
res->writeStatus(uWS::HTTP_200_OK)->write([res](int offset) {