How to say that something is wrong with the server during a response that started with 200 OK. Failed failure

I don't care if there is a standard method in HTTP 1.X to say that there is a problem on the server at the HTTP response stage, which starts with 200 OK.

How to report an error on the server if the 200 OK header is already returned and we are currently sending the response body? In some standards, skillfully.

UPD : there is a duplicate, but without a single response (!) HTTP: an error occurred during the response after the status code OK OK .

To be specific : I cannot use Content-Length to check at the end of the response, because the length cannot be known when the response starts.

Additionally, I cannot cache the entire response on the server before sending it (because it is too large and I will run out of memory and it is too long to generate so that the user cannot wait, etc.)).

+2
source share
1 answer

There is no standard way to do what you want.

To be precise, the standard method is to buffer the response on the server, then send 200 OK and Content-Length, and then the content. As indicated, this does not work for you.

The only alternative I can think of is to wrap the content in some format, which makes it available to detect if it was sent correctly. For example, you can complete it with a hash or even a digital signature. But, obviously, such mechanisms are not part of the HTTP standard.

+3
source

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