adoptium-support icon indicating copy to clipboard operation
adoptium-support copied to clipboard

HTTP/1.1 header parser received no bytes.

Open sblantipodi opened this issue 3 years ago • 12 comments

Hi, the same exact code works well with Adopt JDK15 but not on Adopt JDK16

HttpRequest request = HttpRequest.newBuilder()
                        .header(Constants.UPGRADE_CONTENT_TYPE, Constants.UPGRADE_MULTIPART + boundary)
                        .POST(ofMimeMultipartData(data, boundary))
                        .uri(URI.create(Constants.UPGRADE_URL.replace(Constants.DASH, glowWormDevice.getDeviceIP())))
                        .build();

                client.send(request, HttpResponse.BodyHandlers.discarding());
 /**
     * MimeMultipartData for ESP microcontrollers, standard POST with Java 11 does not work as expected
     * @param data data to be transferred
     * @param boundary boundary
     * @return body publisher
     * @throws IOException something bad happened in the connection
     */
    public static HttpRequest.BodyPublisher ofMimeMultipartData(Map<Object, Object> data, String boundary) throws IOException {

        var byteArrays = new ArrayList<byte[]>();
        byte[] separator = ("--" + boundary + "\r\nContent-Disposition: form-data; name=").getBytes(StandardCharsets.UTF_8);
        for (Map.Entry<Object, Object> entry : data.entrySet()) {
            byteArrays.add(separator);
            if (entry.getValue() instanceof Path) {
                var path = (Path) entry.getValue();
                String mimeType = Files.probeContentType(path);
                byteArrays.add(("\"" + entry.getKey() + "\"; filename=\"" + path.getFileName()
                        + "\"\r\nContent-Type: " + mimeType + "\r\n\r\n").getBytes(StandardCharsets.UTF_8));
                byteArrays.add(Files.readAllBytes(path));
                byteArrays.add("\r\n".getBytes(StandardCharsets.UTF_8));
            } else {
                byteArrays.add(("\"" + entry.getKey() + "\"\r\n\r\n" + entry.getValue() + "\r\n").getBytes(StandardCharsets.UTF_8));
            }
        }
        byteArrays.add(("--" + boundary + "--").getBytes(StandardCharsets.UTF_8));
        return HttpRequest.BodyPublishers.ofByteArrays(byteArrays);

    }

Using JDK16 I get this error:

HTTP/1.1 header parser received no bytes

Any idea on how to fix it? Is this a JDK problem?

Using same code on JDK 15 works well.

sblantipodi avatar Apr 19 '21 14:04 sblantipodi

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar May 05 '22 00:05 github-actions[bot]

https://bugs.openjdk.java.net/browse/JDK-8239117

karianna avatar May 05 '22 10:05 karianna

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar Aug 04 '22 00:08 github-actions[bot]

Bad bot

karianna avatar Aug 04 '22 13:08 karianna

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar Nov 03 '22 00:11 github-actions[bot]

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar Feb 02 '23 00:02 github-actions[bot]

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar May 13 '23 00:05 github-actions[bot]

We are marking this issue as stale because it has not been updated for a while. This is just a way to keep the support issues queue manageable. It will be closed soon unless the stale label is removed by a committer, or a new comment is made.

github-actions[bot] avatar Aug 28 '23 00:08 github-actions[bot]

Should be fixed in https://bugs.openjdk.org/browse/JDK-8299018

Jiehong avatar Feb 21 '24 09:02 Jiehong

And 17.0.7 as as backport.

karianna avatar Feb 22 '24 01:02 karianna

@sblantipodi Can you test and get back to us?

karianna avatar Feb 22 '24 01:02 karianna

My bad, might not be, actually (I reproduced a similar bug with jdk 21).

Ref:

  • https://bugs.openjdk.org/browse/JDK-8239117
  • https://bugs.openjdk.org/browse/JDK-8326420

Jiehong avatar Feb 22 '24 05:02 Jiehong