Support overriding, removing headers in ClientRequest

This commit adds two Consumer based methods to ClientRequest that allow
for direct manipulation of the underlying headers or cookies map. As
such, these methods can be used to override or remove existing entries.

Issue: SPR-15635
This commit is contained in:
Arjen Poutsma
2017-06-08 13:46:37 +02:00
parent e6f1950952
commit bf66f45283
4 changed files with 73 additions and 22 deletions

View File

@@ -51,11 +51,16 @@ public class DefaultClientRequestBuilderTests {
ClientRequest other = ClientRequest.method(GET, URI.create("http://example.com"))
.header("foo", "bar")
.cookie("baz", "qux").build();
ClientRequest result = ClientRequest.from(other).build();
ClientRequest result = ClientRequest.from(other)
.headers(httpHeaders -> httpHeaders.set("foo", "baar"))
.cookies(cookies -> cookies.set("baz", "quux"))
.build();
assertEquals(new URI("http://example.com"), result.url());
assertEquals(GET, result.method());
assertEquals("bar", result.headers().getFirst("foo"));
assertEquals("qux", result.cookies().getFirst("baz"));
assertEquals(1, result.headers().size());
assertEquals("baar", result.headers().getFirst("foo"));
assertEquals(1, result.cookies().size());
assertEquals("quux", result.cookies().getFirst("baz"));
}
@Test