Extra test to check if headers with the same key are maintained.

This commit is contained in:
mathiasdm
2011-02-10 17:09:18 +00:00
parent c8866bebc4
commit 29028342b4
2 changed files with 17 additions and 1 deletions

View File

@@ -365,7 +365,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
}
}
private static String formatHeaders(Map<String, List<String>> headers, StringBuilder command) {
protected static String formatHeaders(Map<String, List<String>> headers, StringBuilder command) {
StringBuilder buf = new StringBuilder(command.length() + headers.size() * 64);
buf.append(command.toString().trim()).append("\r\n");
for (Iterator<String> iter = headers.keySet().iterator(); iter.hasNext(); ) {

View File

@@ -41,5 +41,21 @@ public class I2PTunnelHTTPServerTest extends TestCase {
assertEquals(headers.size(), 1);
assertEquals(headers.get("someHeader").size(), 2);
}
public void testDuplicateHeadersFormat() throws IOException {
String headerString = "GET /something HTTP/1.1\r\n";
headerString += "abc: def\r\n";
headerString += "abc: blaaah\r\n";
headerString += "manamana: toe toe toedoedoe\r\n";
headerString += "\r\n";
InputStream in = fillInputStream(headerString);
StringBuilder builder = new StringBuilder(128);
Map<String, List<String>> headers = I2PTunnelHTTPServer.readHeaders(in, builder, new String[0], null);
String result = I2PTunnelHTTPServer.formatHeaders(headers, builder);
int first = result.indexOf("abc");
assertTrue(first >= 0);
int second = result.indexOf("abc", first);
assertTrue(second >= 0);
}
}