Merge branch '6.2.x'
This commit is contained in:
@@ -59,9 +59,10 @@ import org.springframework.util.ObjectUtils;
|
|||||||
public class HttpEntity<T> {
|
public class HttpEntity<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The empty {@code HttpEntity}, with no body or headers.
|
* An {@code HttpEntity} instance with a {@code null} body and
|
||||||
|
* {@link HttpHeaders#EMPTY empty headers}.
|
||||||
*/
|
*/
|
||||||
public static final HttpEntity<?> EMPTY = new HttpEntity<>();
|
public static final HttpEntity<?> EMPTY = new HttpEntity<>(HttpHeaders.EMPTY);
|
||||||
|
|
||||||
|
|
||||||
private final HttpHeaders headers;
|
private final HttpHeaders headers;
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ import org.junit.jupiter.api.Test;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unit tests for {@link HttpEntity}.
|
||||||
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Yanming Zhou
|
||||||
*/
|
*/
|
||||||
class HttpEntityTests {
|
class HttpEntityTests {
|
||||||
|
|
||||||
@@ -31,6 +34,7 @@ class HttpEntityTests {
|
|||||||
void noHeaders() {
|
void noHeaders() {
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
HttpEntity<String> entity = new HttpEntity<>(body);
|
HttpEntity<String> entity = new HttpEntity<>(body);
|
||||||
|
|
||||||
assertThat(entity.getBody()).isSameAs(body);
|
assertThat(entity.getBody()).isSameAs(body);
|
||||||
assertThat(entity.getHeaders().isEmpty()).as("isEmpty").isTrue();
|
assertThat(entity.getHeaders().isEmpty()).as("isEmpty").isTrue();
|
||||||
}
|
}
|
||||||
@@ -41,6 +45,7 @@ class HttpEntityTests {
|
|||||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
assertThat(entity.getBody()).isEqualTo(body);
|
assertThat(entity.getBody()).isEqualTo(body);
|
||||||
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
|
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
|
||||||
assertThat(entity.getHeaders().getFirst("Content-Type")).isEqualTo("text/plain");
|
assertThat(entity.getHeaders().getFirst("Content-Type")).isEqualTo("text/plain");
|
||||||
@@ -52,6 +57,7 @@ class HttpEntityTests {
|
|||||||
headers.set("Content-Type", "text/plain");
|
headers.set("Content-Type", "text/plain");
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
HttpEntity<String> entity = new HttpEntity<>(body, headers);
|
||||||
|
|
||||||
assertThat(entity.getBody()).isEqualTo(body);
|
assertThat(entity.getBody()).isEqualTo(body);
|
||||||
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
|
assertThat(entity.getHeaders().getContentType()).isEqualTo(MediaType.TEXT_PLAIN);
|
||||||
assertThat(entity.getHeaders().getFirst("Content-Type")).isEqualTo("text/plain");
|
assertThat(entity.getHeaders().getFirst("Content-Type")).isEqualTo("text/plain");
|
||||||
@@ -120,4 +126,14 @@ class HttpEntityTests {
|
|||||||
assertThat(requestEntity2).isEqualTo(requestEntity);
|
assertThat(requestEntity2).isEqualTo(requestEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // gh-34806
|
||||||
|
void mutateEmptyInstanceHeaders() {
|
||||||
|
HttpHeaders headers = new HttpHeaders(HttpEntity.EMPTY.getHeaders());
|
||||||
|
headers.add("Authorization", "Bearer some-token");
|
||||||
|
|
||||||
|
assertThat(HttpEntity.EMPTY.getHeaders())
|
||||||
|
.as("Headers of HttpEntity.EMPTY should remain empty")
|
||||||
|
.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user