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 back dynamically-generated content #1284

Open
s5bug opened this issue Sep 12, 2023 · 0 comments
Open

Streaming back dynamically-generated content #1284

s5bug opened this issue Sep 12, 2023 · 0 comments

Comments

@s5bug
Copy link

s5bug commented Sep 12, 2023

I have a route that ends with code like

if(max.isPresent()) {
    Process p = new ProcessBuilder()
            ...
            .start();

    resp.raw().setContentType("application/octet-stream");
    resp.type("application/octet-stream");

    ServletOutputStream out = resp.raw().getOutputStream();
    p.getInputStream().transferTo(out);
    p.waitFor();
    out.close();

    return 200;
} else {
    return 500;
}

I would like to be able to tell the client that the request succeeded as soon as possible (before I create the process), so that it can start reading down the generated data. To put it another way, I would like to "move" return 200; up to before Process p, so that various HTTP clients can start reading the body ASAP. Is this possible with sparkjava?

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

1 participant