What is the correct HTTP status code for a canceled request

When the TCP connection is canceled by the client when executing the HTTP request, I would like to stop doing any work on the server and return an empty response. What HTTP status code should return such a response?

+4
source share
4 answers

HTTP (1.0 / 1.1) has no means to cancel a request. All the client can do if he no longer wants an answer is to close the connection and hope that the server contains optimizations to stop working on the answer, which can no longer be delivered. Since the connection is now closed, no response or status code can be sent to the client, so any code that you "return" is intended only for your own satisfaction. I would personally choose something in the 4xx 1 range since the “error” is the reason you can no longer deliver the answer is related to the client.

HTTP 2.0 END_STREAM RST_STREAM, , . , , HEADERS DATA, , , , .


1 , 400, , .

+6

, 400 Bad Request , - , , , , Nginx 499 444.

  • 499 , , .

  • 444 , .

+6

( 500, ):

  • 202

    , .

    , "", .

  • 409

    & hellip; .

    : , , .

  • 503

    ( !).

" " 409 503. 503 .

+1

. RFC 7230, 6.5:

, .

This happens at the TCP, and not at the HTTP level. Just stop processing the connection. The status code makes little sense here, since the goal of an incomplete / broken request is just speculation. In addition, there will be no means to transfer it to the client.

+1
source

Source: https://habr.com/ru/post/1685729/


All Articles