RFR: 8355572: Support HTTP Range requests in Simple Web Server [v6]

Michael McMahon michaelm at openjdk.org
Fri Oct 31 15:11:43 UTC 2025


On Fri, 31 Oct 2025 14:53:38 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> src/jdk.httpserver/share/classes/sun/net/httpserver/simpleserver/FileServerHandler.java line 399:
>> 
>>> 397:                     int len = raf.read(buffer, 0, (int) Math.min(buffer.length, bytesToWrite));
>>> 398:                     if (len == -1) {
>>> 399:                         break;  // EOF
>> 
>> Is this not an error situation, if we reach EOF and have only partially returned the requested range?
>
> Good point. But we have already sent the status code. I guess we should throw IOException in this case, so that the ServerImpl closes the connection, ensuring that the client notices that the response was not entirely fulfilled?

I'll have to check the RFC but it might be allowable to return a shorter range than was requested, but the actual range to be returned would have to have been specified in the `Content-Range` header. You would have to check the length of the file first. So, EOF wouldn't occur except in very unusual circumstances. Otherwise, yes throwing IOE would close the connection signaling the error.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28021#discussion_r2481741264


More information about the net-dev mailing list