Introduced parameter sendStatus200 to optionally send the Status

header when the response code is 200.
This commit is contained in:
Simone Bordet 2014-05-20 22:22:25 +02:00
parent 2a4cee5db6
commit 8f9e73df72
5 changed files with 43 additions and 7 deletions

View File

@ -37,9 +37,17 @@ public class ServerGenerator extends Generator
private static final byte[] COLON = new byte[]{':', ' '};
private static final byte[] EOL = new byte[]{'\r', '\n'};
private final boolean sendStatus200;
public ServerGenerator(ByteBufferPool byteBufferPool)
{
this(byteBufferPool, true);
}
public ServerGenerator(ByteBufferPool byteBufferPool, boolean sendStatus200)
{
super(byteBufferPool);
this.sendStatus200 = sendStatus200;
}
public Result generateResponseHeaders(int request, int code, String reason, HttpFields fields, Callback callback)
@ -50,7 +58,7 @@ public class ServerGenerator extends Generator
List<byte[]> bytes = new ArrayList<>(fields.size() * 2);
int length = 0;
if (code > 0)
if (code != 200 || sendStatus200)
{
// Special 'Status' header
bytes.add(STATUS);

View File

@ -40,9 +40,9 @@ public class HttpTransportOverFCGI implements HttpTransport
private volatile boolean shutdown;
private volatile boolean aborted;
public HttpTransportOverFCGI(ByteBufferPool byteBufferPool, Flusher flusher, int request)
public HttpTransportOverFCGI(ByteBufferPool byteBufferPool, Flusher flusher, int request, boolean sendStatus200)
{
this.generator = new ServerGenerator(byteBufferPool);
this.generator = new ServerGenerator(byteBufferPool, sendStatus200);
this.flusher = flusher;
this.request = request;
}

View File

@ -41,16 +41,18 @@ public class ServerFCGIConnection extends AbstractConnection
private final ConcurrentMap<Integer, HttpChannelOverFCGI> channels = new ConcurrentHashMap<>();
private final Connector connector;
private final boolean sendStatus200;
private final Flusher flusher;
private final HttpConfiguration configuration;
private final ServerParser parser;
public ServerFCGIConnection(Connector connector, EndPoint endPoint, HttpConfiguration configuration)
public ServerFCGIConnection(Connector connector, EndPoint endPoint, HttpConfiguration configuration, boolean sendStatus200)
{
super(endPoint, connector.getExecutor());
this.connector = connector;
this.flusher = new Flusher(endPoint);
this.configuration = configuration;
this.sendStatus200 = sendStatus200;
this.parser = new ServerParser(new ServerListener());
}
@ -119,7 +121,8 @@ public class ServerFCGIConnection extends AbstractConnection
{
// TODO: handle flags
HttpChannelOverFCGI channel = new HttpChannelOverFCGI(connector, configuration, getEndPoint(),
new HttpTransportOverFCGI(connector.getByteBufferPool(), flusher, request), new ByteBufferQueuedHttpInput());
new HttpTransportOverFCGI(connector.getByteBufferPool(), flusher, request, sendStatus200),
new ByteBufferQueuedHttpInput());
HttpChannelOverFCGI existing = channels.putIfAbsent(request, channel);
if (existing != null)
throw new IllegalStateException();

View File

@ -27,16 +27,23 @@ import org.eclipse.jetty.server.HttpConfiguration;
public class ServerFCGIConnectionFactory extends AbstractConnectionFactory
{
private final HttpConfiguration configuration;
private final boolean sendStatus200;
public ServerFCGIConnectionFactory(HttpConfiguration configuration)
{
this(configuration, true);
}
public ServerFCGIConnectionFactory(HttpConfiguration configuration, boolean sendStatus200)
{
super("fcgi/1.0");
this.configuration = configuration;
this.sendStatus200 = sendStatus200;
}
@Override
public Connection newConnection(Connector connector, EndPoint endPoint)
{
return new ServerFCGIConnection(connector, endPoint, configuration);
return new ServerFCGIConnection(connector, endPoint, configuration, sendStatus200);
}
}

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.fcgi.server.proxy;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import javax.servlet.ServletException;
@ -43,21 +45,36 @@ import org.eclipse.jetty.util.Callback;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class FastCGIProxyServletTest
{
@Parameterized.Parameters
public static Collection<Object[]> parameters()
{
return Arrays.asList(new Object[]{true}, new Object[]{false});
}
private final boolean sendStatus200;
private Server server;
private ServerConnector httpConnector;
private ServerConnector fcgiConnector;
private HttpClient client;
public FastCGIProxyServletTest(boolean sendStatus200)
{
this.sendStatus200 = sendStatus200;
}
public void prepare(HttpServlet servlet) throws Exception
{
server = new Server();
httpConnector = new ServerConnector(server);
server.addConnector(httpConnector);
fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration()));
fcgiConnector = new ServerConnector(server, new ServerFCGIConnectionFactory(new HttpConfiguration(), sendStatus200));
server.addConnector(fcgiConnector);
final String contextPath = "/";
@ -122,6 +139,7 @@ public class FastCGIProxyServletTest
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
Assert.assertTrue(req.getRequestURI().endsWith(path));
resp.setContentLength(data.length);
resp.getOutputStream().write(data);
}
});