diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpConnection.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpConnection.java index 3c47e39b764e..17dee5cab017 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpConnection.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpConnection.java @@ -20,7 +20,6 @@ import org.eclipse.jetty.client.Authentication; import org.eclipse.jetty.client.AuthenticationStore; -import org.eclipse.jetty.client.BytesRequestContent; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpProxy; import org.eclipse.jetty.client.HttpRequestException; @@ -191,25 +190,25 @@ protected void normalizeRequest(HttpRequest request) // Add content headers. Request.Content content = request.getBody(); - if (content == null) - request.body(content = new BytesRequestContent()); - - if (!headers.contains(HttpHeader.CONTENT_TYPE)) - { - String contentType = content.getContentType(); - if (contentType == null) - contentType = getHttpClient().getDefaultRequestContentType(); - if (contentType != null) - request.addHeader(new HttpField(HttpHeader.CONTENT_TYPE, contentType)); - } - long contentLength = content.getLength(); - if (contentLength >= 0) + if (content != null) { - if (!headers.contains(HttpHeader.CONTENT_LENGTH)) - request.addHeader(new HttpField.LongValueHttpField(HttpHeader.CONTENT_LENGTH, contentLength)); + if (!headers.contains(HttpHeader.CONTENT_TYPE)) + { + String contentType = content.getContentType(); + if (contentType == null) + contentType = getHttpClient().getDefaultRequestContentType(); + if (contentType != null) + request.addHeader(new HttpField(HttpHeader.CONTENT_TYPE, contentType)); + } + long contentLength = content.getLength(); + if (contentLength >= 0) + { + if (!headers.contains(HttpHeader.CONTENT_LENGTH)) + request.addHeader(new HttpField.LongValueHttpField(HttpHeader.CONTENT_LENGTH, contentLength)); + } } // RFC 9110, section 10.1.1. - if (contentLength == 0) + if (content == null || content.getLength() == 0) request.headers(h -> h.remove(HttpHeader.EXPECT)); // Cookies. diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java index 43903c1437a7..55476b7f48ce 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/transport/HttpSender.java @@ -528,7 +528,7 @@ protected Action process() throws Throwable action.run(); // Read the request content. - chunk = content.read(); + chunk = content != null ? content.read() : Content.Chunk.EOF; } if (LOG.isDebugEnabled()) LOG.debug("Content {} for {}", chunk, request); @@ -539,6 +539,7 @@ protected Action process() throws Throwable { // No content after the headers, demand. demanded = true; + assert content != null; content.demand(this::succeeded); return Action.SCHEDULED; }