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

Streaming protocol #1404

Open
rgbkrk opened this issue Oct 28, 2024 · 0 comments
Open

Streaming protocol #1404

rgbkrk opened this issue Oct 28, 2024 · 0 comments

Comments

@rgbkrk
Copy link

rgbkrk commented Oct 28, 2024

Is your feature request related to a problem? Please describe.

I'd love to have a way to push data to the webview in a streaming fashion, whether server sent events or websockets. This got discussed in #420, but is distinctly different as that issue was about asynchronously returning a singular response.

Describe the solution you'd like

Accept Response<Stream<Item = Vec<u8>>> in some manner.

Response (from http) can already accept a Stream

fn stream_response(
    _request: Request<Vec<u8>>,
) -> Result<Response<impl Stream<Item = Vec<u8>> + Send>> {
    let stream = futures::stream::iter(vec![
        "Hello ".as_bytes().to_vec(),
        "World".as_bytes().to_vec(),
    ]);

    Ok(Response::builder()
        .header("Content-Type", "text/plain")
        .status(200)
        .body(stream)
        .unwrap())
}

Where it goes awry is on response via the RequestAsyncResponder, which requires a Response<Into<Cow<'static, [u8]>>>.

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants