Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop request in node.js express

Is it possible using Node.js and express to drop a request for certain route? I.E. not return a http status or any headers? I'd like to just close the connection.

app.get('/drop', function(req, res) {
    //how to drop the request here
});
like image 915
Justin Avatar asked Nov 20 '15 05:11

Justin


1 Answers

To close a connection without returning anything, you can either end() or destroy() the underlying socket.

app.get('/drop', function(req, res) {
  req.socket.end();
});    

I don't think there's any way to drop the connection at your end but keep the client waiting until it times out (i.e. without sending a FIN). You'd perhaps have to interact with your firewall in some way.

like image 133
OrangeDog Avatar answered Oct 21 '22 18:10

OrangeDog