mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 21:39:05 +00:00
Do not send null HTTP header value in JdkClientHttpRequest
Prior to this commit, the `JdkClientHttpRequest` would add all values from `HttpHeaders` to the native request builder. This could cause `NullPointerException` being thrown at runtime because the `HttpClient` does not support that. This commit replicates a fix that was applied to the `SimpleClientHttpRequest`, turning null values into empty "". Fixes gh-35996
This commit is contained in:
+23
@@ -1024,6 +1024,29 @@ class RestClientIntegrationTests {
|
||||
expectRequest(request -> assertThat(request.getHeaders().get("foo")).isEqualTo("bar"));
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void sendNullHeaderValue(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
startServer(requestFactory);
|
||||
|
||||
prepareResponse(builder -> builder
|
||||
.setHeader("Content-Type", "text/plain").body("Hello Spring!"));
|
||||
|
||||
String result = this.restClient.get()
|
||||
.uri("/greeting")
|
||||
.httpRequest(request -> request.getHeaders().add("X-Test-Header", null))
|
||||
.retrieve()
|
||||
.body(String.class);
|
||||
|
||||
assertThat(result).isEqualTo("Hello Spring!");
|
||||
|
||||
expectRequestCount(1);
|
||||
expectRequest(request -> {
|
||||
assertThat(request.getHeaders().get("X-Test-Header")).isNullOrEmpty();
|
||||
assertThat(request.getTarget()).isEqualTo("/greeting");
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void defaultRequest(ClientHttpRequestFactory requestFactory) throws IOException {
|
||||
startServer(requestFactory);
|
||||
|
||||
Reference in New Issue
Block a user