问题
I'm extending this previous question: Aborting a HTTP/1.1 chunk encoded response
When I abort a chunked response Chrome displays a blank page and the dev console reports net::ERR_INCOMPLETE_CHUNKED_ENCODING. IE displays the incomplete page. Is there a way to send the user to an actual 500 error page?
Can I output something that corrupts the document so the browser won't use it? If so, what's the shortest string I can send to achieve this?
回答1:
Unfortunately, there is no chunk you can send that says to the browser "Hey, forget everything I sent so far - something went wrong". Sending a TCP reset packet will cause most browsers to display a "Server reset connection" page, but that requires access to one level down the network stack.
The only other I can think of is to try sending a chunk with a negative length. I don't know how browsers react to that.
回答2:
Here's something interesting I discovered. I'm not sure if it should be applied here, but for consideration:
The HTTP Trailer
header might be a way to insert an invalidating header after the response.
The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer coding.
Another consideration is the Content-MD5
header. An aborted response won't validate. I'm not sure how browsers handle this.
来源:https://stackoverflow.com/questions/27018966/abort-http-chunk-encoded-response-with-error-page