How to report an error halfway through a fragmented HTTP response without closing the connection?

I have an HTTP server that returns large bodies in response to POST requests (this is a SOAP server). These bodies "flow" through the pieces. If I encounter an error halfway through the streaming response, how can I report this error to the client and still keep the connection open? The implementation uses the patented HTTP / SOAP stack, so I'm interested in the answers at the HTTP protocol level.

+3
source share
3 answers

Once the server has sent the client a status bar (the very first response line), you can no longer change the response status code. Many servers delay sending a response, buffering it internally until the buffer is full. As long as the buffer fills up, you can still change your mind about the answer.

If your client has access to response headers, you can use the fact that encoded encoding allows the server to add a trailer with headers after the body with encoded encoding. Thus, your server, faced with an error, can gracefully stop sending the body, and then send a trailer that sets some header for some value. Then your client will interpret the presence of this header as a sign that an error has occurred.

+2
source

, " " , HTTP-. , :

X-RealStatus: 500 Some bad stuff happened

, :

X-RealStatus: 200 OK
+2

you can change the status code as long as response.iscommitted () returns false. (fot HttpServletResponse in java, I'm sure there is an equivalent in other languages)

0
source

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


All Articles