adoptium / adoptium/adoptium-support

HTTP/1.1 header parser received no bytes.

Open
#292 12 comments 0 reactions 0 assignees View on GitHub
bug jbs:reported keep Waiting on OP
Dominant language
No language data
Stars
59
Forks
13
PR merge metrics
No merged PRs in 30d

Description

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 data, String boundary) throws IOException {

var byteArrays = new ArrayList();
byte[] separator = ("--" + boundary + "\r\nContent-Disposition: form-data; name=").getBytes(StandardCharsets.UTF_8);
for (Map.Entry 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.

Contributor guide

Open the contributing guide

Research direction

No repository files or tests are named. Start by reproducing the request through HttpRequest.newBuilder(), client.send(), and ofMimeMultipartData() on Adopt JDK15 and JDK16, then compare the generated request and server response. Done means identifying whether the regression is in JDK16 or the multipart request and recording a verified fix or reproducible JDK issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.