Fix NPE when calling NettyHeadersAdapter.add()

Prior to this commit, the `NettyHeadersAdapter` would directly delegate
the `add()` and `set()` calls to the adapted
`io.netty.handler.codec.http.HttpHeaders`. This implementation rejects
`null` values with exceptions.

This commit aligns the behavior here with other implementations, by not
rejecting null values but simply ignoring them.

Fixes gh-26277
(cherry-picked from commit 83c19cd60e)
This commit is contained in:
Brian Clozel
2020-12-15 13:23:53 +01:00
parent cfdceae70f
commit fe26b7d3fd
2 changed files with 14 additions and 2 deletions

View File

@@ -94,6 +94,14 @@ class HeadersAdaptersTests {
assertThat(headers.get("TestHeader").size()).isEqualTo(1);
}
@ParameterizedHeadersTest
void nullValuesShouldNotFail(String displayName, MultiValueMap<String, String> headers) {
headers.add("TestHeader", null);
assertThat(headers.getFirst("TestHeader")).isNull();
headers.set("TestHeader", null);
assertThat(headers.getFirst("TestHeader")).isNull();
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@ParameterizedTest(name = "[{index}] {0}")