mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Fix missing request body for GET and DELETE JdkClientHttpRequest
This commit fixes a regression introduced in gh-34971 where GET and DELETE requests would not allow request bodies anymore for `JdkClientHttpRequest`. We are now using `builder.GET()` and `builder.DELETE()` methods only if the provided body is null. Fixes gh-35068
This commit is contained in:
+24
-24
@@ -149,37 +149,37 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
}
|
||||
});
|
||||
|
||||
switch (this.method.name()) {
|
||||
case "GET" :
|
||||
builder.GET();
|
||||
break;
|
||||
case "DELETE" :
|
||||
builder.DELETE();
|
||||
break;
|
||||
default :
|
||||
builder.method(this.method.name(), bodyPublisher(headers, body));
|
||||
if (body != null) {
|
||||
builder.method(this.method.name(), bodyPublisher(headers, body));
|
||||
}
|
||||
else {
|
||||
switch (this.method.name()) {
|
||||
case "GET" :
|
||||
builder.GET();
|
||||
break;
|
||||
case "DELETE" :
|
||||
builder.DELETE();
|
||||
break;
|
||||
default :
|
||||
builder.method(this.method.name(), HttpRequest.BodyPublishers.noBody());
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, @Nullable Body body) {
|
||||
if (body != null) {
|
||||
Flow.Publisher<ByteBuffer> publisher = new OutputStreamPublisher<>(
|
||||
os -> body.writeTo(StreamUtils.nonClosing(os)), BYTE_MAPPER, this.executor, null);
|
||||
private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, Body body) {
|
||||
Flow.Publisher<ByteBuffer> publisher = new OutputStreamPublisher<>(
|
||||
os -> body.writeTo(StreamUtils.nonClosing(os)), BYTE_MAPPER, this.executor, null);
|
||||
|
||||
long contentLength = headers.getContentLength();
|
||||
if (contentLength > 0) {
|
||||
return HttpRequest.BodyPublishers.fromPublisher(publisher, contentLength);
|
||||
}
|
||||
else if (contentLength == 0) {
|
||||
return HttpRequest.BodyPublishers.noBody();
|
||||
}
|
||||
else {
|
||||
return HttpRequest.BodyPublishers.fromPublisher(publisher);
|
||||
}
|
||||
long contentLength = headers.getContentLength();
|
||||
if (contentLength > 0) {
|
||||
return HttpRequest.BodyPublishers.fromPublisher(publisher, contentLength);
|
||||
}
|
||||
else if (contentLength == 0) {
|
||||
return HttpRequest.BodyPublishers.noBody();
|
||||
}
|
||||
else {
|
||||
return HttpRequest.BodyPublishers.noBody();
|
||||
return HttpRequest.BodyPublishers.fromPublisher(publisher);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user