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

Any plans to add async iterator support to IncomingMessage? #277

Closed
hbgl opened this issue Aug 3, 2023 · 5 comments
Closed

Any plans to add async iterator support to IncomingMessage? #277

hbgl opened this issue Aug 3, 2023 · 5 comments

Comments

@hbgl
Copy link
Contributor

hbgl commented Aug 3, 2023

Node's http.IncomingMessage inherits from stream.Readable which implements the async iterator protocol in recent versions of Node. It would be appropriate for the mock to also have support for it. A use case would be converting an http.IncomingMessage to a web Request:

import { IncomingMessage } from 'http';

function incomingMessageToRequest(incomingMessage: IncomingMessage) {
    return new Request('...', {
        method: '...',
        body: incomingMessage, // Body supports any async iterable
        duplex: 'half',
    });
}

It would help me fix this issue in Astro: withastro/astro#7525 (comment)

@eugef
Copy link
Owner

eugef commented Aug 7, 2023

Hi @hbgl, there are no plans to implement this feature.

So I'd like encourage you to create a PR wow add a missing functionality.

@hbgl
Copy link
Contributor Author

hbgl commented Aug 8, 2023

Hello @eugef, thanks for the reply. I will create a PR for this new feature once I am done. It will require Node version >= 10 because that is when async iterator support was added.

As an aside, I would not give up on properly extending from ReadableStream (old PR) which already comes with async iterator support baked in among other things. One could even think about extending IncomingMessage directly. In any case, it would probably be a breaking change.

@eugef
Copy link
Owner

eugef commented Aug 8, 2023

We are currently supporting Node.js 14 and above, so you can safely use async iterators

@hbgl
Copy link
Contributor Author

hbgl commented Aug 8, 2023

We are currently supporting Node.js 14 and above, so you can safely use async iterators

I saw this line in the package.json

"engines": {
"node": ">=0.6"
},

So I was unsure if adding async iterators would be a problem. Thanks for clearing that up.

@eugef
Copy link
Owner

eugef commented Aug 9, 2023

Thanks for pointing out, I will fix it straight away

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

2 participants