Simple node.js proxy by piping http server to http request

后端 未结 3 761
北恋
北恋 2020-12-08 03:31

Trying to learn more about node.js by making a simple http proxy server. The use scenario is simple: user -> proxy -> server -> proxy -> user

The following code work

3条回答
  •  爱一瞬间的悲伤
    2020-12-08 03:45

    you dont have to 'pause', just 'pipe' is ok

    var connector = http.request(options, function(res) {
      res.pipe(response, {end:true});//tell 'response' end=true
    });
    request.pipe(connector, {end:true});
    

    http request will not finish until you tell it is 'end';

提交回复
热议问题