简体   繁体   中英

Nodejs proxy with request and response modification

I want to write a Nodejs module which acts as a proxy, and modifies the request (body and headers) before forwarding the request to a backend service and then modifies the response received (body and headers) from the backend service before responding back to the client. The request protocol is going to be http.

I want to use the node http module to write this but have the following doubts :

  1. Will it be better to create a persistent http connection with the backend service (using keep-alive) ? What are the caveats ? Does node http have separate timeout configs for connection and request ?
  2. Or, is it ok to use the http request without keepalive ? Will this be less performant when put under significant load compared to #1 ?

The main concern is regarding the performance difference/benefit between the two approaches when running on a load. I feel the first approach with keepAlive will perform better due to lesser connections being formed.

I believe you should go for the keepalive in this case as you're only making a single connection towards a server, you should gain some performance benefits, especially if you have multiple clients sending requests to your proxy service. You needn't modify the maxSockets as they already default to infinity if I remember correctly. Most http requests that clients send to your proxy should be keep-alive by default too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM