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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user