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:
Brian Clozel
2025-12-11 09:40:42 +01:00
parent c89c4ac614
commit 23625ee698
3 changed files with 25 additions and 2 deletions
@@ -155,7 +155,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
headers.forEach((headerName, headerValues) -> {
if (!DISALLOWED_HEADERS.contains(headerName.toLowerCase(Locale.ROOT))) {
for (String headerValue : headerValues) {
builder.header(headerName, headerValue);
builder.header(headerName, (headerValue != null) ? headerValue : "");
}
}
});
@@ -90,7 +90,7 @@ class OkHttp3ClientHttpRequest extends AbstractStreamingClientHttpRequest {
builder.method(this.method.name(), requestBody);
headers.forEach((headerName, headerValues) -> {
for (String headerValue : headerValues) {
builder.addHeader(headerName, headerValue);
builder.addHeader(headerName, (headerValue != null) ? headerValue : "");
}
});
Request request = builder.build();