JDKHttpClient: Handle RQST with no Body [POST/PUT]
Fixes:
@@ -115,7 +115,12 @@ private BodyPublisher notChunkingBodyPublisher(HttpRequest req) {
if (length == null) {
// read the data into a byte array to know the length
- return BodyPublishers.ofByteArray(Contents.bytes(req.getContent()));
+ byte[] bytes = Contents.bytes(req.getContent());
+ if (bytes.length == 0) {
+ //Looks like we were given a request with no payload.
+ return BodyPublishers.noBody();
+ }
+ return BodyPublishers.ofByteArray(bytes);
}
// we know the length of the request and use it
