2016-06-23 7 views
0

私はこのnodejsコードを持っていますが、正直言って私は.pipeが何をしているのかよく分かりません。この場合Nodejs要求パイプは応答を終了します

var localoptions = { 
    url: requestUrl, 
    milliseconds, default is 2 seconds 
}; 


if (authHeader) { 
    localoptions.headers = { 
    "Authorization": authHeader 
    }; 
} 

request(localoptions) 
.on('error', function(e) { 
res.end(e); 
}).pipe(res); 

RESは特定のルートを処理する関数からの応答です。

この場合、.pipeはレスポンスのレスポンスを終了しますか?

答えて

0

あなたは、宛先がソース終了するとすぐに閉じられますストリームにパイプ

readable.pipe(destination[, options])を(あなたがオプションとしてendコールバックを渡すと予想される)場合:

options<Object>パイプオプション
end<Boolean>リーダーが終了したらライターを終了します。デフォルトはtrueです。

そして、ここでソース node: stream.js

// If the 'end' option is not supplied, dest.end() will be called when 
// source gets the 'end' or 'close' events. Only dest.end() once. 
if (!dest._isStdio && (!options || options.end !== false)) { 
    source.on('end', onend); 
    source.on('close', onclose); 
} 

var didOnEnd = false; 
function onend() { 
    if (didOnEnd) return; 
    didOnEnd = true; 

    dest.end(); 
} 
で対応する部分
関連する問題