Make headers.set(self) a no-op instead of throwing. Makes it consistent with setAll
Motivation: Makes the API contract of headers more consistent and simpler. Modifications: If self is passed to set then simply return Result: set and setAll will be consistent
This commit is contained in:
parent
6504d52b94
commit
3eb65797ed
@ -79,9 +79,11 @@ public class HttpHeadersTest {
|
|||||||
headers.add(headers);
|
headers.add(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testSetSelf() {
|
public void testSetSelfIsNoOp() {
|
||||||
HttpHeaders headers = new DefaultHttpHeaders(false);
|
HttpHeaders headers = new DefaultHttpHeaders(false);
|
||||||
|
headers.add("name", "value");
|
||||||
headers.set(headers);
|
headers.set(headers);
|
||||||
|
assertEquals(1, headers.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -543,7 +543,7 @@ public class DefaultHeaders<K, V, T extends Headers<K, V, T>> implements Headers
|
|||||||
public T set(Headers<? extends K, ? extends V, ?> headers) {
|
public T set(Headers<? extends K, ? extends V, ?> headers) {
|
||||||
checkNotNull(headers, "headers");
|
checkNotNull(headers, "headers");
|
||||||
if (headers == this) {
|
if (headers == this) {
|
||||||
throw new IllegalArgumentException("can't add to itself.");
|
return thisT();
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
if (headers instanceof DefaultHeaders) {
|
if (headers instanceof DefaultHeaders) {
|
||||||
|
@ -390,9 +390,11 @@ public class DefaultHeadersTest {
|
|||||||
headers.add(headers);
|
headers.add(headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void testSetSelf() {
|
public void testSetSelfIsNoOp() {
|
||||||
TestDefaultHeaders headers = newInstance();
|
TestDefaultHeaders headers = newInstance();
|
||||||
|
headers.add("name", "value");
|
||||||
headers.set(headers);
|
headers.set(headers);
|
||||||
|
assertEquals(1, headers.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user