mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Use HTTP methods in JdkClientHttpRequest when possible
Prior to this commit, we would use the `java.net.http.HttpRequest.Builder#method(String, BodyPublisher)` to create HTTP requests for the JDK HttpClient. This method requires a non-null body publisher; providing an empty publisher writes a "Content-Length: 0" header to all requests. As of Java 19, this behavior changes for `HttpRequest.Builder#GET` and similar methods, where the body publisher is considered as null and no "Content-Length" header is written. This commit aligns with this behavior and favors dedicated HTTP methods whenever available.` Closes gh-34971
This commit is contained in:
@@ -149,7 +149,16 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
|
||||
}
|
||||
});
|
||||
|
||||
builder.method(this.method.name(), bodyPublisher(headers, body));
|
||||
switch (this.method.name()) {
|
||||
case "GET" :
|
||||
builder.GET();
|
||||
break;
|
||||
case "DELETE" :
|
||||
builder.DELETE();
|
||||
break;
|
||||
default :
|
||||
builder.method(this.method.name(), bodyPublisher(headers, body));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user