Skip to content

Commit

Permalink
Merge pull request #1279 from stuartwdouglas/headers-test
Browse files Browse the repository at this point in the history
[UNDERTOW-2006] Add test that headers of different case work
  • Loading branch information
fl4via committed Dec 13, 2021
2 parents 6ac611d + cd08fc5 commit b24d455
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ public void testSimpleRequest() throws BadRequestException {
runTest(in);
}

@Test
public void testDifferentCaseHeaders() throws BadRequestException {
final ParseState context = new ParseState(10);
HttpServerExchange result = new HttpServerExchange(null);
byte[] in = "GET /somepath HTTP/1.1\r\nHost: www.somehost.net\r\nhost: other\r\n\r\n".getBytes();
HttpRequestParser.instance(OptionMap.EMPTY).handle(ByteBuffer.wrap(in), context, result);
Assert.assertArrayEquals(result.getRequestHeaders().get("HOST").toArray(), new String[] {"www.somehost.net", "other"});
}

@Test(expected = BadRequestException.class)
public void testTabInsteadOfSpaceAfterVerb() throws BadRequestException {
byte[] in = "GET\t/somepath HTTP/1.1\r\nHost: www.somehost.net\r\nOtherHeader: some\r\n value\r\n\r\n".getBytes();
Expand Down
13 changes: 12 additions & 1 deletion core/src/test/java/io/undertow/util/HeaderMapTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
Expand All @@ -47,6 +48,16 @@ public void testInitial() {
assertFalse(headerMap.iterator().hasNext());
}

@Test
public void testMixedCase() {
final HeaderMap headerMap = new HeaderMap();
headerMap.add(new HttpString("Aa"), "A");
headerMap.add(new HttpString("aa"), "a");
assertArrayEquals(headerMap.get(new HttpString("aa")).toArray(), new String[]{"A", "a"});
assertArrayEquals(headerMap.get(new HttpString("Aa")).toArray(), new String[]{"A", "a"});
assertArrayEquals(headerMap.get(new HttpString("AA")).toArray(), new String[]{"A", "a"});
}

@Test
public void testSimple() {
final HeaderMap headerMap = new HeaderMap();
Expand All @@ -68,7 +79,7 @@ public void testSimple() {
public void testGrowing() {
final HeaderMap headerMap = new HeaderMap();
for (HttpString item : HTTP_STRING_LIST) {
for (int i = 0; i < (item.hashCode() & 7) + 1; i ++)
for (int i = 0; i < (item.hashCode() & 7) + 1; i++)
headerMap.add(item, "Test value");
}
for (HttpString item : HTTP_STRING_LIST) {
Expand Down

0 comments on commit b24d455

Please sign in to comment.