434447 Able to create a session after a response.sendRedirect

This commit is contained in:
Jan Bartel 2014-05-12 11:22:41 +02:00
parent ce36613604
commit ca5a086877
2 changed files with 39 additions and 0 deletions

View File

@ -1397,6 +1397,9 @@ public class Request implements HttpServletRequest
if (!create)
return null;
if (getResponse().isCommitted())
throw new IllegalStateException("Response is committed");
if (_sessionManager == null)
throw new IllegalStateException("No SessionManager");

View File

@ -26,6 +26,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.BufferedReader;
import java.io.File;
@ -712,6 +713,41 @@ public class RequestTest
}
@Test
public void testSessionAfterRedirect() throws Exception
{
Handler handler = new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException
{
baseRequest.setHandled(true);
response.sendRedirect("/foo");
try
{
request.getSession(true);
fail("Session should not be created after response committed");
}
catch (IllegalStateException e)
{
//expected
}
catch (Exception e)
{
fail("Session creation after response commit should throw IllegalStateException");
}
}
};
_server.stop();
_server.setHandler(handler);
_server.start();
String response=_connector.getResponses("GET / HTTP/1.1\n"+
"Host: myhost\n"+
"Connection: close\n"+
"\n");
}
@Test
public void testPartialInput() throws Exception
{