nxtedition/node-http2-proxy

onReq param 2 (options) no longer the same thing in 5.x?

risacher opened this issue · 2 comments

The following code works for me with http2-proxy 4.2.15, but not with 5.0.30:

   proxy.web(req, res,                                                                                                                                                                        
              { onReq: (req, options, cb) => {                                                                                                                                                 
                  options.headers['x-forwarded-for'] = req.socket.remoteAddress;                                                                                                               
                  options.headers['x-forwarded-port'] = req.socket.localPort;                                                                                                                  
                  options.headers['x-forwarded-proto'] = req.socket.encrypted ? 'https' : 'http';                                                                                              
                  options.headers['x-forwarded-host'] = req.headers['host'];                                                                                                                   
                  options.headers['host'] = req.headers['host'];                                                                                                                               
                  options.rejectUnauthorized = false;                                                                                                                                          
                  options.trackRedirects = true;                                                                                                                                               
                  options.host = target.host;                                                                                                                                                  
                  options.hostname = target.hostname;                                                                                                                                          
                  options.port = target.port;                                                                                                                                                  
                  options.path = target.path;                                                                                                                                                  
                  options.protocol = target.protocol+':';                                                                                                                                      
                                                                                                                                                                                               
                  var r = (target.protocol === 'http')?                                                                                                                                        
                      http.request(options)                                                                                                                                                    
                      : https.request(options);                                                                                                                                                
                  return r;                                                                                                                                                                    
                },                                                                                                                                                                             
              }, defaultWebHandler );                                                                                                                                                          

In 5.0.30, the options parameter to onReq does not have a 'headers' entry, and in fact, equals{ onReq: [Function: onReq] }, but this does not seem to agree with the documentation in README.md.

ronag commented

Yep, that's a bug. Try 5.0.31.

5.0.31 fixes the immediate problem I was having, and now I've got a different problem - all of my proxied connections say Error: socket hang up

Since I don't know what's causing this at the moment, I'll close #28 and reopen a new bug once I've narrowed that down.