On Wed, 26 Jun 2024 14:35:57 GMT, Daniel Jeliński <djelin...@openjdk.org> wrote:
> Currently HttpUrlConnection accepts truncated responses: if the server sends > a `Content-Length` header, and then closes the connection before transferring > all promised bytes, the input stream reports a clean EOF. > > In this PR I modify the MeteredStream class to throw an IOException when it > detects EOF before receiving all promised response bytes. MeteredStream (or > its subclass KeepAliveStream) is used when the response contains a > content-length header. > > The included test fails without the change, passes with it. > The same exception message and type is reported when a chunked response > (`Transfer-Encoding: chunked`) is truncated. > Unknown length responses that are terminated by EOF continue to work. > > 2 tests depended on the old behavior and had to be adjusted. The remaining > tier 1-3 tests continue to pass. This pull request has now been integrated. Changeset: b6ffb442 Author: Daniel Jeliński <djelin...@openjdk.org> URL: https://git.openjdk.org/jdk/commit/b6ffb442acb4a222f017868433eff213d9b84ed8 Stats: 120 lines in 4 files changed: 115 ins; 0 del; 5 mod 8335135: HttpURLConnection#HttpInputStream does not throw IOException when response is truncated Reviewed-by: dfuchs ------------- PR: https://git.openjdk.org/jdk/pull/19909