尝试使用
Readable.wrap:
var Readable = require('stream').Readable;...function (request, reply) { var s = Request('http://www.google.com'); reply(new Readable().wrap(s));}使用Node 0.10.x和hapi 8.xx进行了测试。在我的代码示例
Request中,node-
request模块
request是传入的hapi请求对象。
更新
另一种可能的解决办法是监听“响应”事件从
Request然后
reply用
http.IncomingMessage这是一个适当的读操作流。
function (request, reply) { Request('http://www.google.com') .on('response', function (response) { reply(response); });}这需要较少的步骤,并且还允许开发人员在传输之前将用户定义的属性附加到流。这对于设置200以外的状态代码很有用。



