On Mon, 30 Mar 2026 10:46:46 GMT, Jaikiran Pai <[email protected]> wrote:

>> test/jdk/java/net/HttpURLConnection/ProxyBadStatusLine.java line 216:
>> 
>>> 214:         }
>>> 215: 
>>> 216:         private static byte[] readRequest(InputStream is) throws 
>>> IOException {
>> 
>> I've two remarks regarding this method:
>> 
>> 1. It doesn't handle the case when double-CRLF is not found, yet EOF is 
>> reached.
>> 2. It can use some diet using `Arrays::mismatch` and `::copyOfRange`:
>> 
>>        private static byte[] readRequest(InputStream is) throws IOException {
>>            // we don't expect the HTTP request body in this test to be 
>> larger than this size
>>            final byte[] buff = new byte[4096];
>>            int numRead = 0;
>>            boolean found = false;
>>            byte[] delimiter = {'\r', '\n', '\r', '\n'};
>>            for (int c; !found && (c = is.read()) != -1 && numRead < 
>> buff.length;) {
>>                buff[numRead++] = (byte) c;
>>                if (numRead >= delimiter.length) {
>>                    found = Arrays.mismatch(buff, numRead - delimiter.length, 
>> numRead, delimiter, 0, delimiter.length) < 0;
>>                }
>>            }
>>            if (!found) {
>>                throw new IOException(
>>                        "Couldn't locate double-CRLF in request: " +
>>                                new String(buff, 0, numRead, ISO_8859_1));
>>            }
>>            return Arrays.copyOfRange(buff, 0, numRead);
>>        }
>
>> It doesn't handle the case when double-CRLF is not found, yet EOF is reached.
> 
> That's a good point. I've updated that part of the test to throw an error if 
> the CRLFCRLF sequence wasn't located in the request.

> It can use some diet using Arrays::mismatch and ::copyOfRange

I find the current style a bit easier to read (and I borrowed it from the 
existing ProxyServer test library). I can change it to the style you suggest if 
you prefer that one better.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30466#discussion_r3009012649

Reply via email to