Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Streaming Response Feature #995

Closed
ferjif opened this issue Aug 23, 2021 · 3 comments
Closed

Add Streaming Response Feature #995

ferjif opened this issue Aug 23, 2021 · 3 comments

Comments

@ferjif
Copy link

ferjif commented Aug 23, 2021

Use Cases
When I want to send notifications to the client or when i want to stream webcam images to the client I need to use streaming responses. if you look at EventSource and also server-sent-events in the mozilla developer network you can see some of the use cases for streaming responses specially for server-sent-events. also for video streaming and webcam image streaming there are many examples. if you search for webcam streaming or http live stream (HLS) you'll find many examples specially in python.

Solution

drogon::app().registerHandler([](const drogon::HttpRequestPtr& req, std::function<void(const drogon::ResponsePtr&)>&& callback)
{
    //....
    while(true)
    {
        callback(resp);
    }
}

or maybe

drogon::app().registerHandler([](const drogon::HttpRequestPtr& req, std::function<void(const drogon::ResponsePtr&)>&& callback)
{
    //....
    callback(resp);
    while(true)
    {
        resp.append(content);
    }
}

Alternatives in different languages

  • the examples and doc for every framework is provided using a hyperlink.
    in c++ the wt and oat++ frameworks have this concept implemented. in python django, sanic and other frameworks have implamented this concept. in Java there is jooby and other frameworks which have implemented this feature. I haven't implemented any streaming web servers in other languages but since webcam (mjpeg) streaming and server-sent-events are standards and are used industry wide other languages and frameworks have probably implemented them.
@AmissLake
Copy link

It's an important improvement !!! I was wondering if drogon had it. I really need this implementation

@louwers
Copy link

louwers commented Nov 3, 2021

Django doesn't really support streaming...

Interesting take on SSE vs Websockets: https://stackoverflow.com/questions/28582935/does-http-2-make-websockets-obsolete

Probably better to watch this first: #349

@hwc0919
Copy link
Member

hwc0919 commented May 27, 2022

See #1156

@hwc0919 hwc0919 closed this as completed May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants