Make HttpHeaders.set(self) a no-op consistently rather than having some implementations throw and others not
This commit is contained in:
parent
fd810e7178
commit
4af06799ea
@ -77,15 +77,14 @@ public class DefaultHttpHeaders extends HttpHeaders {
|
||||
@Override
|
||||
public HttpHeaders set(HttpHeaders headers) {
|
||||
if (headers instanceof DefaultHttpHeaders) {
|
||||
if (headers == this) {
|
||||
throw new IllegalArgumentException("can't add to itself.");
|
||||
}
|
||||
clear();
|
||||
DefaultHttpHeaders defaultHttpHeaders = (DefaultHttpHeaders) headers;
|
||||
HeaderEntry e = defaultHttpHeaders.head.after;
|
||||
while (e != defaultHttpHeaders.head) {
|
||||
add(e.key, e.value);
|
||||
e = e.after;
|
||||
if (headers != this) {
|
||||
clear();
|
||||
DefaultHttpHeaders defaultHttpHeaders = (DefaultHttpHeaders) headers;
|
||||
HeaderEntry e = defaultHttpHeaders.head.after;
|
||||
while (e != defaultHttpHeaders.head) {
|
||||
add(e.key, e.value);
|
||||
e = e.after;
|
||||
}
|
||||
}
|
||||
return this;
|
||||
} else {
|
||||
|
@ -1617,9 +1617,11 @@ public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>>
|
||||
if (headers == null) {
|
||||
throw new NullPointerException("headers");
|
||||
}
|
||||
clear();
|
||||
for (Map.Entry<String, String> e: headers) {
|
||||
add(e.getKey(), e.getValue());
|
||||
if (headers != this) {
|
||||
clear();
|
||||
for (Map.Entry<String, String> e : headers) {
|
||||
add(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -74,9 +74,12 @@ public class HttpHeadersTest {
|
||||
headers.add(headers);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetSelf() {
|
||||
@Test
|
||||
public void testSetSelfIsNoOp() {
|
||||
HttpHeaders headers = new DefaultHttpHeaders(false);
|
||||
headers.add("some", "thing");
|
||||
headers.set(headers);
|
||||
Assert.assertEquals(1, headers.entries().size());
|
||||
Assert.assertEquals("thing", headers.get("some"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user