File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change 4949 *
5050 * @author Arjen Poutsma
5151 * @author Juergen Hoeller
52+ * @author Yanming Zhou
5253 * @since 3.0.2
5354 * @param <T> the body type
5455 * @see org.springframework.web.client.RestTemplate
@@ -60,7 +61,7 @@ public class HttpEntity<T> {
6061 /**
6162 * The empty {@code HttpEntity}, with no body or headers.
6263 */
63- public static final HttpEntity <?> EMPTY = new HttpEntity <>();
64+ public static final HttpEntity <?> EMPTY = new HttpEntity <>(HttpHeaders . EMPTY );
6465
6566
6667 private final HttpHeaders headers ;
Original file line number Diff line number Diff line change 2727
2828/**
2929 * @author Arjen Poutsma
30+ * @author Yanming Zhou
3031 */
3132class HttpEntityTests {
3233
@@ -123,4 +124,11 @@ void requestEntity() {
123124 assertThat (requestEntity2 ).isEqualTo (requestEntity );
124125 }
125126
127+ @ Test
128+ void emptyHttpEntityShouldBeImmutable () {
129+ HttpHeaders newHeaders = new HttpHeaders (HttpEntity .EMPTY .getHeaders ());
130+ newHeaders .add ("Authorization" , "Bearer some-token" );
131+ assertThat (HttpEntity .EMPTY .getHeaders ().headerNames ()).isEmpty ();
132+ }
133+
126134}
You can’t perform that action at this time.
0 commit comments