crow icon indicating copy to clipboard operation
crow copied to clipboard

response streaming interface - chunked transfer encoding

Open jhruby opened this issue 9 years ago • 3 comments

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

jhruby avatar Sep 26 '16 22:09 jhruby

this project seem been abandoned by the author @ipkn.

see issue #37 and notice the issue date, you will know what i mean.

FTAndy avatar Dec 26 '16 01:12 FTAndy

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 ...

jhruby avatar Jan 02 '17 10:01 jhruby

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

legokichi avatar Apr 05 '18 13:04 legokichi