nodejs / undici

An HTTP/1.1 client, written from scratch for Node.js
https://nodejs.github.io/undici
MIT License
6.17k stars 536 forks source link

pipeline doesn't support objectMode #221

Closed ronag closed 4 years ago

ronag commented 4 years ago

Currently it is not possible to return an object stream through client.pipeline.

e.g.

client.pipeline(options, ({ body }) => {
  return pipeline(body, jsonParser, () => {}) // jsonParse is a string => object transform
})

Is this something that makes sense to support and if so how?

Should pipeline always be readableObjectMode, what are the downside of that? Or should pipeline have a objectMode parameter in options?

ronag commented 4 years ago

@mcollina @kmamal

mcollina commented 4 years ago

Is this a problem?

kmamal commented 4 years ago

I encountered this when requesting an rss feed and trying to pipe() the returned body to feedparser inside the handler. I was able to work around the limitation by moving the pipe() outside the handler.

That would have been a lot trickier to do if I needed to look at one of the headers to decide what to pipe to (for example piping to either an ndjson or xml parser based on content-type).