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

Piping Stream to Response Yields Empty Result #24

Closed
JD-Robbs opened this issue Aug 19, 2016 · 7 comments
Closed

Piping Stream to Response Yields Empty Result #24

JD-Robbs opened this issue Aug 19, 2016 · 7 comments

Comments

@JD-Robbs
Copy link
Contributor

Consider the following example of piping a stream (any stream; but my example uses PDF) to the result object:

@Get("/pdf")
public pdf(@Req() req: Request, @Res() res: Response) {
    let wkhtmltopdf = require("wkhtmltopdf");

    res.setHeader("Content-type", "application/pdf");
    wkhtmltopdf("http://localhost/my/app").pipe(res);
}

Unfortunately, the route simply returns Cannot GET /pdf.

The same code, however, works when conventionally registering the route as below.
I wonder if I'm doing something wrong, or if the piping of streams is not yet supported.

app.get("/test", (req: Request, res: Response) => {
    let wkhtmltopdf = require("wkhtmltopdf");

    res.setHeader("Content-type", "application/pdf");
    wkhtmltopdf("http://localhost/projects/proposely").pipe(res);
});
@pleerock
Copy link
Contributor

I haven't tested pipes support, I need deeper investigation of this issue. Do you know what wkhtmltopdf("...").pipe(res); does inside? Does it use request.send somehow?

btw this is offtopic, but you can use @Header("Content-type", "application/pdf") instead of res.setHeader("Content-type", "application/pdf");

@Diluka
Copy link
Contributor

Diluka commented Sep 12, 2016

If I call res.send manually, there must be an error Can't set headers after they are sent.

@felipesabino
Copy link
Contributor

Any news on this? I am having the same issue trying to return a stream with binary data

Error: write after end

@pleerock
Copy link
Contributor

I recommend to use old school res and return using it until I come back to this issue.

@pleerock pleerock mentioned this issue Apr 24, 2017
@ajmalmsali
Copy link

@felipesabino any updates?

@pleerock
Copy link
Contributor

this should be fixed in 0.7.0. If its not please create a new issue.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants