From 3707a56c8a5297620330c228521786d94df10b84 Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Tue, 20 Dec 2022 08:58:32 +0530 Subject: [PATCH] JDKHttpClient: Handle RQST with no Body [POST/PUT] Fixes: #11342 --- .../openqa/selenium/remote/http/jdk/JdkHttpMessages.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java index 8aae9ab2bc52ba..5aca1b2401de59 100644 --- a/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java +++ b/java/src/org/openqa/selenium/remote/http/jdk/JdkHttpMessages.java @@ -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