crow
crow copied to clipboard
response streaming interface - chunked transfer encoding
Hi, this an awesome project.
Would be nice to support chunked encoding for streaming outputs. So we can return content of arbitrary size without wasting memory.
Jan
this project seem been abandoned by the author @ipkn.
see issue #37 and notice the issue date, you will know what i mean.
Would be great that someone would implement this kind of high level framework on top of http://blincubator.com/bi_library/beast-2/?gform_post_id=1579
That library look as a good stable base for such a library ...
boost beast integration seems good.
#include <boost/program_options.hpp>
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/http.hpp>
#include "crow_all_stream.h"
auto main() -> int {
namespace asio = boost::asio;
namespace http = boost::beast::http;
crow::SimpleApp app;
CROW_ROUTE(app, "/foo")
([](http::request<http::string_body> req, asio::ip::tcp::socket& socket){
asio::spawn(*(req.io_service), [&](auto const yield){
try{
auto res = http::response<http::string_body>{http::status::ok, req.version()};
res.set(http::field::content_type, "text/html");
res.keep_alive(req.keep_alive());
res.body() = std::string{"hi!"};
res.prepare_payload();
http::async_write(socket, res, yield);
socket.close();
}catch (std::exception& err){
}
});
});
app.port(18080).run();
}
and using AsyncWriteStream