forked from I2P_Developers/i2p.i2p
merge of '710537602a9f16aa4235ee5d50f9062658827469'
and 'ebeebe3477f791c404683923ccfaf075de781391'
This commit is contained in:
@@ -141,6 +141,52 @@
|
||||
splitindex="true"
|
||||
windowtitle="I2PTunnel" />
|
||||
</target>
|
||||
|
||||
<target name="compileTest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
<classpath>
|
||||
<pathelement location="../../../core/java/build/i2p.jar" />
|
||||
<pathelement location="../../ministreaming/java/build/mstreaming.jar" />
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
<target name="test" depends="clean, compileTest">
|
||||
<junit printsummary="on" fork="yes">
|
||||
<classpath>
|
||||
<pathelement path="${classpath}" />
|
||||
<pathelement location="./build/obj" />
|
||||
<pathelement location="../../../core/java/build/i2p.jar" />
|
||||
</classpath>
|
||||
<batchtest>
|
||||
<fileset dir="./test/">
|
||||
<include name="**/*Test.java" />
|
||||
</fileset>
|
||||
</batchtest>
|
||||
<formatter type="xml"/>
|
||||
</junit>
|
||||
<mkdir dir="../../../reports/" />
|
||||
<mkdir dir="../../../reports/i2ptunnel/" />
|
||||
<mkdir dir="../../../reports/i2ptunnel/junit/" />
|
||||
<delete>
|
||||
<fileset dir="../../../reports/i2ptunnel/junit">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
<copy todir="../../../reports/i2ptunnel/junit">
|
||||
<fileset dir=".">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<delete>
|
||||
<fileset dir=".">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="clean">
|
||||
<delete dir="./build" />
|
||||
<delete dir="../jsp/WEB-INF/" />
|
||||
|
@@ -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(); ) {
|
||||
@@ -418,7 +418,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, List<String>> readHeaders(InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx) throws IOException {
|
||||
protected static Map<String, List<String>> readHeaders(InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx) throws IOException {
|
||||
HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
|
||||
StringBuilder buf = new StringBuilder(128);
|
||||
|
||||
|
@@ -0,0 +1,61 @@
|
||||
package net.i2p.i2ptunnel;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class I2PTunnelHTTPServerTest extends TestCase {
|
||||
|
||||
public InputStream fillInputStream(String headers) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos));
|
||||
bw.write(headers);
|
||||
bw.flush();
|
||||
byte[] bytes = baos.toByteArray();
|
||||
return new ByteArrayInputStream(bytes);
|
||||
}
|
||||
|
||||
public void testSimpleHeader() throws IOException {
|
||||
String headerString = "GET /blah HTTP/1.1\r\n";
|
||||
headerString += "BLAH: something\r\n";
|
||||
headerString += "\r\n";
|
||||
InputStream in = fillInputStream(headerString);
|
||||
Map<String, List<String>> headers = I2PTunnelHTTPServer.readHeaders(in, new StringBuilder(128), new String[0], null);
|
||||
assertEquals(headers.size(), 1); //One header
|
||||
}
|
||||
|
||||
public void testDuplicateHeader() throws IOException {
|
||||
String headerString = "GET /something HTTP/1.1\r\n";
|
||||
headerString += "someHeader: blabla bla bloooo\r\n";
|
||||
headerString += "someHeader: oh my, duplication!\r\n";
|
||||
headerString += "\r\n";
|
||||
InputStream in = fillInputStream(headerString);
|
||||
Map<String, List<String>> headers = I2PTunnelHTTPServer.readHeaders(in, new StringBuilder(128), new String[0], null);
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user