Handle response content-length mis-match errors #175
Description
If the application sets the content-length response header and then does not write that exact number of bytes then this corrupts the connection state. There are three scenarios:
A) The application writes more bytes than specified. The client will truncate at the specified content-length and then fail trying to parse the remainder as the start of the next response. The client should then abort the connection.
B) The applications writes fewer bytes than specified. The client will hang waiting for the remaining data. Eventually it should time out and disconnect.
C) The application specifies a non-zero content length but doesn't write any data. The client will hang just as in (B)
For (A) it would be nice to track the content length and throw from Write if too many bytes are written. The connection should be aborted.
For (B) we need to track the content length and disconnect if the response ends without writing enough data. There's no way to raise this error to the application except in the logs. This scenario should be treated the same as if there were an unhandled exception after the response body had started.
(C) we could detect even without tracking content written because we know if the response has started or not. The response should be changed to a 500 internal server error and logged as an error.