Merge branch 'jetty-9.4.x'
This commit is contained in:
commit
e47052f706
|
@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -33,7 +34,6 @@ import org.eclipse.jetty.http.HttpTester;
|
||||||
import org.eclipse.jetty.http.HttpVersion;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
import org.eclipse.jetty.server.LocalConnector;
|
import org.eclipse.jetty.server.LocalConnector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -59,7 +59,12 @@ public class ResponseHeadersTest
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException
|
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException
|
||||||
{
|
{
|
||||||
// The bad use-case
|
// The bad use-case
|
||||||
response.setHeader("X-example", req.getPathInfo());
|
String pathInfo = req.getPathInfo();
|
||||||
|
if(pathInfo != null && pathInfo.length() > 1 && pathInfo.startsWith("/"))
|
||||||
|
{
|
||||||
|
pathInfo = pathInfo.substring(1);
|
||||||
|
}
|
||||||
|
response.setHeader("X-example", pathInfo);
|
||||||
|
|
||||||
// The correct use
|
// The correct use
|
||||||
response.setContentType("text/plain");
|
response.setContentType("text/plain");
|
||||||
|
@ -122,19 +127,26 @@ public class ResponseHeadersTest
|
||||||
@Test
|
@Test
|
||||||
public void testMultilineResponseHeaderValue() throws Exception
|
public void testMultilineResponseHeaderValue() throws Exception
|
||||||
{
|
{
|
||||||
|
String actualPathInfo = "%0A%20Content-Type%3A%20image/png%0A%20Content-Length%3A%208%0A%20%0A%20yuck<!--";
|
||||||
|
|
||||||
HttpTester.Request request = new HttpTester.Request();
|
HttpTester.Request request = new HttpTester.Request();
|
||||||
request.setMethod("GET");
|
request.setMethod("GET");
|
||||||
request.setURI("/multiline/%0A%20Content-Type%3A%20image/png%0A%20Content-Length%3A%208%0A%20%0A%20yuck<!--");
|
request.setURI("/multiline/" + actualPathInfo);
|
||||||
request.setVersion(HttpVersion.HTTP_1_1);
|
request.setVersion(HttpVersion.HTTP_1_1);
|
||||||
request.setHeader("Connection", "close");
|
request.setHeader("Connection", "close");
|
||||||
request.setHeader("Host", "test");
|
request.setHeader("Host", "test");
|
||||||
|
|
||||||
ByteBuffer responseBuffer = connector.getResponse(request.generate());
|
ByteBuffer responseBuffer = connector.getResponse(request.generate());
|
||||||
System.err.println(BufferUtil.toUTF8String(responseBuffer));
|
// System.err.println(BufferUtil.toUTF8String(responseBuffer));
|
||||||
HttpTester.Response response = HttpTester.parseResponse(responseBuffer);
|
HttpTester.Response response = HttpTester.parseResponse(responseBuffer);
|
||||||
|
|
||||||
// Now test for properly formatted HTTP Response Headers.
|
// Now test for properly formatted HTTP Response Headers.
|
||||||
assertThat("Response Code",response.getStatus(),is(200));
|
assertThat("Response Code",response.getStatus(),is(200));
|
||||||
assertThat("Response Header Content-Type",response.get("Content-Type"),is("text/plain;charset=UTF-8"));
|
assertThat("Response Header Content-Type",response.get("Content-Type"),is("text/plain;charset=UTF-8"));
|
||||||
|
|
||||||
|
String expected = actualPathInfo.replaceAll("%0A", " "); // replace OBS fold with space
|
||||||
|
expected = URLDecoder.decode(expected, "utf-8"); // decode the rest
|
||||||
|
expected = expected.trim(); // trim whitespace at start/end
|
||||||
|
assertThat("Response Header X-example", response.get("X-Example"), is(expected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue