mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Merge branch '6.2.x'
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-1
@@ -96,10 +96,21 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-35068
|
||||
void deleteRequestWithBody() throws Exception {
|
||||
URI uri = URI.create(baseUrl + "/echo");
|
||||
ClientHttpRequest request = this.factory.createRequest(uri, HttpMethod.DELETE);
|
||||
StreamUtils.copy("body", StandardCharsets.ISO_8859_1, request.getBody());
|
||||
try (ClientHttpResponse response = request.execute()) {
|
||||
assertThat(response.getStatusCode()).as("Invalid response status").isEqualTo(HttpStatus.OK);
|
||||
assertThat(StreamUtils.copyToString(response.getBody(), StandardCharsets.ISO_8859_1))
|
||||
.as("Invalid request body").isEqualTo("body");
|
||||
}
|
||||
}
|
||||
|
||||
@Test // gh-34971
|
||||
@EnabledForJreRange(min = JRE.JAVA_19) // behavior fixed in Java 19
|
||||
void requestContentLengthHeader() throws Exception {
|
||||
void requestContentLengthHeaderWhenNoBody() throws Exception {
|
||||
URI uri = URI.create(baseUrl + "/header/Content-Length");
|
||||
assertNoContentLength(uri, HttpMethod.GET);
|
||||
assertNoContentLength(uri, HttpMethod.DELETE);
|
||||
|
||||
Reference in New Issue
Block a user