Skip to content

Commit 02b3801

Browse files
committed
Merge branch '6.1.x'
2 parents 69eaf8f + 64b0283 commit 02b3801

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

spring-web/src/main/java/org/springframework/http/client/AbstractBufferingClientHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,7 @@ protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
4242
@Override
4343
protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
4444
byte[] bytes = this.bufferedOutput.toByteArrayUnsafe();
45-
if (bytes.length > 0 && headers.getContentLength() < 0) {
45+
if (headers.getContentLength() < 0) {
4646
headers.setContentLength(bytes.length);
4747
}
4848
ClientHttpResponse result = executeInternal(headers, bytes);

spring-web/src/test/java/org/springframework/http/client/AbstractMockWebServerTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ else if(request.getPath().startsWith("/methods/")) {
106106
assertThat(request.getMethod()).isEqualTo(expectedMethod);
107107
return new MockResponse();
108108
}
109-
else if(request.getPath().startsWith("/header/")) {
110-
String headerName = request.getPath().replace("/header/","");
111-
return new MockResponse().setBody(headerName + ":" + request.getHeader(headerName)).setResponseCode(200);
112-
}
113109
return new MockResponse().setResponseCode(404);
114110
}
115111
catch (Throwable exc) {

spring-web/src/test/java/org/springframework/http/client/BufferingClientHttpRequestFactoryTests.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.http.client;
1818

19-
import java.io.InputStreamReader;
2019
import java.net.URI;
2120
import java.nio.charset.StandardCharsets;
2221
import java.util.Arrays;
@@ -50,7 +49,12 @@ void repeatableRead() throws Exception {
5049
FileCopyUtils.copy(body, request.getBody());
5150
try (ClientHttpResponse response = request.execute()) {
5251
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
52+
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
53+
54+
assertThat(response.getHeaders().containsKey(headerName)).as("Header not found").isTrue();
5355
assertThat(response.getHeaders().containsKey(headerName)).as("Header not found").isTrue();
56+
57+
assertThat(response.getHeaders().get(headerName)).as("Header value not found").isEqualTo(Arrays.asList(headerValue1, headerValue2));
5458
assertThat(response.getHeaders().get(headerName)).as("Header value not found").isEqualTo(Arrays.asList(headerValue1, headerValue2));
5559

5660
byte[] result = FileCopyUtils.copyToByteArray(response.getBody());
@@ -60,14 +64,4 @@ void repeatableRead() throws Exception {
6064
}
6165
}
6266

63-
@Test
64-
void shouldNotSetContentLengthWhenEmptyBody() throws Exception {
65-
ClientHttpRequest request = factory.createRequest(URI.create(baseUrl + "/header/Content-Length"), HttpMethod.POST);
66-
try (ClientHttpResponse response = request.execute()) {
67-
assertThat(response.getStatusCode()).as("Invalid status code").isEqualTo(HttpStatus.OK);
68-
String result = FileCopyUtils.copyToString(new InputStreamReader(response.getBody()));
69-
assertThat(result).as("Invalid body").isEqualTo("Content-Length:null");
70-
}
71-
}
72-
7367
}

0 commit comments

Comments
 (0)