title: Handling CONNECT requests with node.js express module
body: <p>My node app is receiving some mysterious <code>CONNECT</code> requests and I'm trying to get to the bottom of where these are coming from (see separate post <a href="https://stackoverflow.com/q/33370798/4070848">here</a>).</p>
  
  <p>I'm using the <a href="https://www.npmjs.com/package/express" rel="nofollow noreferrer">express module</a> and until now, incoming <code>CONNECT</code> requests would just be fended off automatically with a <code>503</code> response.</p>
  
  <p>But now, in order to examine the headers of these <code>CONNECT</code> requests, I'm trying to implement handling of such requests using the <code>express</code> module, if only just to dump the headers to the console and then send a <code>503</code> response myself.</p>
  
  <p>Given the <code>express</code> seems to provide handling of <code>connect</code> as well as <code>get</code> and <code>post</code> (see <a href="http://expressjs.com/4x/api.html#app.METHOD" rel="nofollow noreferrer">here</a>), this is what I've tried so far:</p>
  
  <pre><code>var connectHandler = function(req, res) {
      console.log(JSON.stringify(req.headers));
      res.sendStatus(503);
  };
  
  var app = express();
  app.connect('*', connectHandler);
  </code></pre>
  
  <p>But the behaviour of the node app doesn't change... i.e. nothing is dumped to console when an incoming <code>CONNECT</code> request is received, with the <code>CONNECT</code> request being fended off and with the following entry in the log (just as before):</p>
  
  <pre><code>Oct 27 14:14:25 example heroku/router: at=error code=H13 desc="Connection closed without response" method=CONNECT path="example.herokuapp.com:443" host=example.herokuapp.com request_id=353e623x-dec4-42x5-bcfb-452add02ecef fwd="111.22.333.4" dyno=web.1 connect=0ms service=1ms status=503 bytes=0
  </code></pre>
  
  <p>Any help appreciated.</p>