Bug 334311 fix buffer reuse issue in CachedExchange
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2663 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
639223361a
commit
3c664563be
|
@ -25,6 +25,7 @@ jetty-7.3.0-SNAPSHOT
|
|||
+ 333679 refactor jetty-jmx to support the OSGi PAX tests.
|
||||
+ 334062 It should be possible to embed in the jetty.home.bundle the ssl keystore files
|
||||
+ 334229 javax-security needs to import the package javax.security.cert in its OSGi manifest
|
||||
+ 334311 fix buffer reuse issue in CachedExchange
|
||||
|
||||
jetty-7.2.2.v20101205 5 December 2010
|
||||
+ JETTY-1308 327109 (re)fixed AJP handling of empty packets
|
||||
|
|
|
@ -60,7 +60,10 @@ public class CachedExchange extends HttpExchange
|
|||
protected synchronized void onResponseHeader(Buffer name, Buffer value) throws IOException
|
||||
{
|
||||
if (_responseFields != null)
|
||||
_responseFields.add(name, value);
|
||||
{
|
||||
_responseFields.add(name, value.asImmutableBuffer());
|
||||
}
|
||||
|
||||
super.onResponseHeader(name, value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.client.CachedExchange;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
|
||||
public class CachedHeadersIsolationTest extends TestCase
|
||||
{
|
||||
|
||||
Server server;
|
||||
HttpClient client;
|
||||
int port;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
server = new Server();
|
||||
|
||||
Connector connector = new SelectChannelConnector();
|
||||
|
||||
server.addConnector(connector);
|
||||
|
||||
server.setHandler(new AbstractHandler()
|
||||
{
|
||||
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException,
|
||||
ServletException
|
||||
{
|
||||
response.setStatus(HttpStatus.OK_200);
|
||||
response.addHeader("For",request.getQueryString());
|
||||
response.addHeader("Name","Value");
|
||||
response.getOutputStream().print("blah");
|
||||
response.flushBuffer();
|
||||
}
|
||||
});
|
||||
|
||||
server.start();
|
||||
|
||||
port = server.getConnectors()[0].getLocalPort();
|
||||
|
||||
client = new HttpClient();
|
||||
client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
|
||||
client.setConnectTimeout(5);
|
||||
client.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception
|
||||
{
|
||||
super.tearDown();
|
||||
server.stop();
|
||||
client.stop();
|
||||
}
|
||||
|
||||
public void testHeaderWhenReadEarly() throws Exception
|
||||
{
|
||||
|
||||
CachedExchange e1 = new CachedExchange(true);
|
||||
CachedExchange e2 = new CachedExchange(true);
|
||||
|
||||
e1.setURL("http://localhost:" + port + "/?a=short");
|
||||
e2.setURL("http://localhost:" + port + "/?a=something_longer");
|
||||
|
||||
client.send(e1);
|
||||
while (!e1.isDone())
|
||||
Thread.sleep(100);
|
||||
|
||||
assertEquals("Read buffer","Value",e1.getResponseFields().getStringField("Name"));
|
||||
|
||||
client.send(e2);
|
||||
while (!e2.isDone())
|
||||
Thread.sleep(100);
|
||||
|
||||
assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name"));
|
||||
}
|
||||
|
||||
public void testHeaderWhenReadLate() throws Exception
|
||||
{
|
||||
|
||||
CachedExchange e1 = new CachedExchange(true);
|
||||
CachedExchange e2 = new CachedExchange(true);
|
||||
|
||||
e1.setURL("http://localhost:" + port + "/?a=short");
|
||||
e2.setURL("http://localhost:" + port + "/?a=something_longer");
|
||||
|
||||
client.send(e1);
|
||||
while (!e1.isDone())
|
||||
Thread.sleep(100);
|
||||
|
||||
client.send(e2);
|
||||
while (!e2.isDone())
|
||||
Thread.sleep(100);
|
||||
|
||||
for ( Enumeration<String> e = e1.getResponseFields().getValues("Name"); e.hasMoreElements();)
|
||||
{
|
||||
System.out.println(e.nextElement());
|
||||
}
|
||||
|
||||
assertEquals("Overwritten buffer","Value",e1.getResponseFields().getStringField("Name"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue