0

My node app is receiving some mysterious CONNECT requests and I'm trying to get to the bottom of where these are coming from (see separate post here).

I'm using the express module and until now, incoming CONNECT requests would just be fended off automatically with a 503 response.

But now, in order to examine the headers of these CONNECT requests, I'm trying to implement handling of such requests using the express module, if only just to dump the headers to the console and then send a 503 response myself.

Given the express seems to provide handling of connect as well as get and post (see here), this is what I've tried so far:

var connectHandler = function(req, res) {
    console.log(JSON.stringify(req.headers));
    res.sendStatus(503);
};

var app = express();
app.connect('*', connectHandler);

But the behaviour of the node app doesn't change... i.e. nothing is dumped to console when an incoming CONNECT request is received, with the CONNECT request being fended off and with the following entry in the log (just as before):

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

Any help appreciated.

Community
  • 1
  • 1
drmrbrewer
  • 11,491
  • 21
  • 85
  • 181
  • 1
    Do you see the CONNECT request if you use a generic middleware (e.g. `app.use()`) ? – mscdex Nov 05 '15 at 09:28
  • Good suggestion @mscdex. But when I do something like `app.use(function (req, res, next) { console.log(req.method, JSON.stringify(req.headers)); next(); });` it *is* seeing e.g. `HEAD` requests from a ping service I'm using, but unfortunately it does *not* seem to be seeing the `CONNECT` requests. – drmrbrewer Nov 05 '15 at 13:59
  • Ok, if you have that test generic middleware *at the top* of your Express router stack and you're not seeing the CONNECT requests, then something else is at play here. – mscdex Nov 05 '15 at 20:40
  • Yep, I was starting to think the same, so I've already put in a question to heroku to see if they can understand what's going on, and whether their system is somehow intercepting CONNECTs before they even get to my app – drmrbrewer Nov 06 '15 at 08:05
  • The reply from heroku (who, as ever, are amazing) explains it all: "as described in our routing docs (https://devcenter.heroku.com/articles/http-routing#supported-http-methods), we support all HTTP verbs except the CONNECT verb. So, the response being sent is from our router – not your application. That explains why your application is never receiving the request." So the generic middleware solution above would probably (normally) work, and maybe even the `app.connect()` approach in my question... I'll probably never know! – drmrbrewer Nov 06 '15 at 20:47
  • Technically both of them should work in a normal/unrestricted environment. – mscdex Nov 07 '15 at 05:04

0 Answers0