Skip to content

HttpEntity.EMPTY headers should not be possible to mutate via HttpHeaders constructor #34812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @author Yanming Zhou
* @since 3.0.2
* @param <T> the body type
* @see org.springframework.web.client.RestTemplate
Expand All @@ -61,7 +62,7 @@ public class HttpEntity<T> {
/**
* The empty {@code HttpEntity}, with no body or headers.
*/
public static final HttpEntity<?> EMPTY = new HttpEntity<>();
public static final HttpEntity<?> EMPTY = new HttpEntity<>(HttpHeaders.EMPTY);


private final HttpHeaders headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* @author Arjen Poutsma
* @author Yanming Zhou
*/
class HttpEntityTests {

Expand Down Expand Up @@ -120,4 +121,11 @@ void requestEntity() {
assertThat(requestEntity2).isEqualTo(requestEntity);
}

@Test
void emptyHttpEntityShouldBeImmutable() {
HttpHeaders newHeaders = new HttpHeaders(HttpEntity.EMPTY.getHeaders());
newHeaders.add("Authorization", "Bearer some-token");
assertThat(HttpEntity.EMPTY.getHeaders().headerNames()).isEmpty();
}

}
Loading