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

Ability to access request.body as a stream in API routes #7661

Closed
kevva opened this issue Jun 25, 2019 · 3 comments
Closed

Ability to access request.body as a stream in API routes #7661

kevva opened this issue Jun 25, 2019 · 3 comments

Comments

@kevva
Copy link
Contributor

kevva commented Jun 25, 2019

When handling API requests, we always try to parse the body depending on headers etc (see https://github.com/zeit/next.js/blob/canary/packages/next-server/server/api-utils.ts#L12-L39). However, in some cases you maybe don't want to save the whole body into memory but rather pipe it to some other stream to save memory. It'd be nice if we had access to the original body somewhere, or if we introduced an option to turn this off.

I initially discovered the use for this when trying to parse multipart/form-data which most libraries expect to be a stream, but there might be other uses for this as well.

@Janpot
Copy link
Contributor

Janpot commented Jun 25, 2019

There will be an opt-out #7363 (comment). No idea as of what form of shape that will be.

EDIT:

Would like to add that to my preference, the opt-out wouldn't be configured the way AMP is configured, i.e. through a static config export. It should be possible for 3rd-party libraries to configure the opt-out themselves. For instance by having a property on the handler to signal to next it wants the original request/response objects.

// third-party lib
export api () {
  function api (req, res) {
    req.pipe(myProxy).pipe(res);
  }
  api[Symbol.for('nextjs-opt-out')] = true;
  return api;
}

// /api/handler.js
import { api } from 'third-party';
export default api();

@huv1k
Copy link
Contributor

huv1k commented Jun 28, 2019

This was fixed with #7686 thx for reporting @kevva

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants