As an HTTP 1.1 server, I respond to a GET request with a status code of 200 OK, and then send the data to the client. An error occurs during this submission, and I cannot finish.
I cannot send a new status code because the final status code has already been sent.
How should I behave to inform the client about the error, and I can not continue this HTTP request?
I can only think of one solution: close the socket, but it is not perfect: it interrupts the keep-alive function, and a clear explanation of the error is not provided to the client.
The HTTP standard seems to assume that the server already knows exactly what to respond before it starts to respond. But it's not always the case. Examples: I am returning a very large file (several GB) from the disk, and I am getting an I / O error at some point while reading the file. The same example with a large dump of DB.
I cannot build my entire answer in memory and then send it.
The HTTP 1.1 standard helps for this use with packet-encoded encoding: I donβt even need to know the final size before starting to send a response. Therefore, this use is not excluded from HTTP 1.1.
source share