[#1690] Correctly return first header value on DefaultHttpHeaders.get(..)
This commit is contained in:
parent
20a010a2ea
commit
3b94154893
@ -221,14 +221,16 @@ public class DefaultHttpHeaders extends HttpHeaders {
|
||||
int h = hash(name);
|
||||
int i = index(h);
|
||||
HeaderEntry e = entries[i];
|
||||
String value = null;
|
||||
// loop until the first header was found
|
||||
while (e != null) {
|
||||
if (e.hash == h && eq(name, e.key)) {
|
||||
return e.value;
|
||||
value = e.value;
|
||||
}
|
||||
|
||||
e = e.next;
|
||||
}
|
||||
return null;
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,6 +18,8 @@ package io.netty.handler.codec.http;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HttpHeadersTest {
|
||||
|
||||
@Test
|
||||
@ -27,4 +29,19 @@ public class HttpHeadersTest {
|
||||
HttpHeaders.removeTransferEncodingChunked(message);
|
||||
Assert.assertTrue(message.headers().isEmpty());
|
||||
}
|
||||
|
||||
// Test for https://github.com/netty/netty/issues/1690
|
||||
@Test
|
||||
public void testGetOperations() {
|
||||
HttpHeaders headers = new DefaultHttpHeaders();
|
||||
headers.add("Foo", "1");
|
||||
headers.add("Foo", "2");
|
||||
|
||||
Assert.assertEquals("1", headers.get("Foo"));
|
||||
|
||||
List<String> values = headers.getAll("Foo");
|
||||
Assert.assertEquals(2, values.size());
|
||||
Assert.assertEquals("1", values.get(0));
|
||||
Assert.assertEquals("2", values.get(1));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user