What is the Correct HTTP Status Code for a Cancelled Request

Muhammad Rehan Saeed picture Muhammad Rehan Saeed · Sep 15, 2017 · Viewed 31.1k times · Source

When a TCP connection gets cancelled by the client while making a HTTP request, I'd like to stop doing any work on the server and return an empty response. What HTTP status code should such a response return?

Answer

nbari picture nbari · Sep 22, 2017

To be consistent I would suggest 400 Bad Request now if your backend apps are capable of identifying when the client gets disconnected or if you reject or close the connection, probably you could return Nginx' non-standard code 499 or 444.

  • 499 Client Closed Request Used when the client has closed the request before the server could send a response.

  • 444 No Response Used to indicate that the server has returned no information to the client and closed the connection.