From 29028342b4c8a12ee0654527bf5660cbc688c091 Mon Sep 17 00:00:00 2001 From: mathiasdm <mathiasdm@mail.i2p> Date: Thu, 10 Feb 2011 17:09:18 +0000 Subject: [PATCH] Extra test to check if headers with the same key are maintained. --- .../net/i2p/i2ptunnel/I2PTunnelHTTPServer.java | 2 +- .../i2p/i2ptunnel/I2PTunnelHTTPServerTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index bafa0387cf..4e8fdf6c97 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -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(); ) { diff --git a/apps/i2ptunnel/java/test/net/i2p/i2ptunnel/I2PTunnelHTTPServerTest.java b/apps/i2ptunnel/java/test/net/i2p/i2ptunnel/I2PTunnelHTTPServerTest.java index f35787e558..8cd7cf3227 100644 --- a/apps/i2ptunnel/java/test/net/i2p/i2ptunnel/I2PTunnelHTTPServerTest.java +++ b/apps/i2ptunnel/java/test/net/i2p/i2ptunnel/I2PTunnelHTTPServerTest.java @@ -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); + } } -- GitLab