Reputation: 4000
What is the most efficient method to have Django selectively/conditionally ignore a request (don't return anything) and drop the connection (don't block future requests)?
Upvotes: 2
Views: 2268
Reputation: 53679
It is generally not possible for a WSGI application to drop a request without sending a response. Not returning anything is an error, and the WSGI server will respond with an appropriate error message indicating the application is not working as expected. Even if your WSGI server does not return a response, your web server will simply handle it as a timeout and send a 504 Gateway Timeout.
If you're using nginx as your public-facing webserver, you can send a response from Django with a status code of 444, i.e. return HttpResponse(status=444)
. If nginx receives this status code from an upstream server, it will drop the request without a response. As far as I know, nginx is the only webserver to provide this option.
If you can't use nginx, I'm afraid there's no option at a webserver level.
Upvotes: 7