Closed kevinsimper closed 9 years ago
Could you share a full example?
does it work if you pipe to a require('stream').PassThrough()
, the node core implementation?
@juliangruber No, it does not, was does that tell? @mafintosh I just tried to replicate the problem in a condensed script, which works perfectly (irritating) https://gist.github.com/kevinsimper/5b962095aea3cb833d6c
But basicly a express app that proxies requests, it works perfect without throught2, so that is good, but whenever I insert through2 into the pipes, it fails.
I tried zlib.createGUnzip and zlib.createGzip because I did not know if it was because I was reading gziped and passing on something else, but did get any clevere.
var proxyRequest = request({
url: url,
method: req.method,
headers: {
'Host': host
}
})
req
.pipe(through2()) // Works fine if leaved in
.pipe(proxyRequest)
.pipe(through2()) // does not work when inserted here, even through it should just pass through to res
.pipe(res)
request actually does a lot of magic stuff with the destination you pipe it to (https://github.com/request/request/blob/master/request.js#L1338-L1356) like setting headers if it's a http response. by inserting the passthrough stream you loose this. could it be related to something like this?
@mafintosh Yes, your right! Thanks for the hint!
Pretty stupid to rewrite pipe just to make it magic without mentioning it in the docs. You would assume using other libs that pipe is standard across all, but apparently not.
I am using through2 to inspect a stream that i proxy.
But they input is not the same as the output apparently, even if i do a pass through stream like this:
I also tried
.pipe(through2({decodeStrings: false}))
, but that did not help.How can that be? I am piping a
request
to a node httpres
. I am really lost on this!and according to the docs if you do not pass anything it