Merge branch 'master' of github.com:intalio/jetty-fcgi
This commit is contained in:
commit
e00f5c4056
|
@ -36,7 +36,6 @@ public class Flusher
|
|||
private final Queue<Generator.Result> queue = new ConcurrentArrayQueue<>();
|
||||
private final Callback flushCallback = new FlushCallback();
|
||||
private final EndPoint endPoint;
|
||||
private boolean flushing;
|
||||
|
||||
public Flusher(EndPoint endPoint)
|
||||
{
|
||||
|
@ -48,10 +47,9 @@ public class Flusher
|
|||
synchronized (queue)
|
||||
{
|
||||
for (Generator.Result result : results)
|
||||
{
|
||||
queue.offer(result);
|
||||
if (flushing)
|
||||
return;
|
||||
flushing = true;
|
||||
}
|
||||
}
|
||||
endPoint.write(flushCallback);
|
||||
}
|
||||
|
@ -68,27 +66,15 @@ public class Flusher
|
|||
@Override
|
||||
protected boolean process() throws Exception
|
||||
{
|
||||
// We are flushing, we completed a write, notify
|
||||
if (active != null)
|
||||
{
|
||||
active.succeeded();
|
||||
active = null;
|
||||
}
|
||||
|
||||
// Look if other writes are needed.
|
||||
Generator.Result result;
|
||||
synchronized (queue)
|
||||
{
|
||||
if (queue.isEmpty())
|
||||
{
|
||||
// No more writes to do, switch to non-flushing
|
||||
flushing = false;
|
||||
return false;
|
||||
}
|
||||
// TODO: here is where we want to gather more results to perform gathered writes
|
||||
result = queue.poll();
|
||||
}
|
||||
|
||||
active = result;
|
||||
List<ByteBuffer> buffers = result.getByteBuffers();
|
||||
endPoint.write(this, buffers.toArray(new ByteBuffer[buffers.size()]));
|
||||
|
@ -101,18 +87,22 @@ public class Flusher
|
|||
// Nothing to do, we always return false from process().
|
||||
}
|
||||
|
||||
@Override
|
||||
public void succeeded()
|
||||
{
|
||||
if (active != null)
|
||||
active.succeeded();
|
||||
active = null;
|
||||
super.succeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable x)
|
||||
{
|
||||
super.failed(x);
|
||||
|
||||
// TODO: set flushing=false ?
|
||||
|
||||
if (active != null)
|
||||
{
|
||||
active.failed(x);
|
||||
active = null;
|
||||
}
|
||||
active = null;
|
||||
super.failed(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.fcgi.client.http;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.client.AbstractHttpClientTransport;
|
||||
import org.eclipse.jetty.client.HttpDestination;
|
||||
import org.eclipse.jetty.client.api.Connection;
|
||||
|
@ -26,14 +28,22 @@ import org.eclipse.jetty.io.EndPoint;
|
|||
// TODO: add parameter to tell whether use multiplex destinations or not
|
||||
public class HttpClientTransportOverFCGI extends AbstractHttpClientTransport
|
||||
{
|
||||
public HttpClientTransportOverFCGI()
|
||||
private final Pattern uriPattern;
|
||||
|
||||
public HttpClientTransportOverFCGI(Pattern uriPattern)
|
||||
{
|
||||
this(1);
|
||||
this(1, uriPattern);
|
||||
}
|
||||
|
||||
public HttpClientTransportOverFCGI(int selectors)
|
||||
public HttpClientTransportOverFCGI(int selectors, Pattern uriPattern)
|
||||
{
|
||||
super(selectors);
|
||||
this.uriPattern = uriPattern;
|
||||
}
|
||||
|
||||
public Pattern getURIPattern()
|
||||
{
|
||||
return uriPattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.eclipse.jetty.fcgi.client.http;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.jetty.client.HttpChannel;
|
||||
import org.eclipse.jetty.client.HttpContent;
|
||||
|
@ -52,11 +54,20 @@ public class HttpSenderOverFCGI extends HttpSender
|
|||
|
||||
headers.put(FCGI.Headers.GATEWAY_INTERFACE, "CGI/1.1");
|
||||
|
||||
HttpClientTransportOverFCGI transport = (HttpClientTransportOverFCGI)getHttpChannel().getHttpDestination().getHttpClient().getTransport();
|
||||
Pattern uriPattern = transport.getURIPattern();
|
||||
Matcher matcher = uriPattern.matcher(uri.toString());
|
||||
|
||||
// TODO: what if the URI does not match ? Here is kinda too late to abort the request ?
|
||||
// TODO: perhaps this works in conjuntion with the ProxyServlet, which is mapped to the same URI regexp
|
||||
// TODO: so that if the call arrives here, we are sure it matches.
|
||||
|
||||
// headers.put(Headers.PATH_INFO, ???);
|
||||
// headers.put(Headers.PATH_TRANSLATED, ???);
|
||||
|
||||
headers.put(FCGI.Headers.QUERY_STRING, uri.getQuery());
|
||||
|
||||
// TODO: the fields below are probably provided by ProxyServlet as X-Forwarded-*
|
||||
// headers.put(Headers.REMOTE_ADDR, ???);
|
||||
// headers.put(Headers.REMOTE_HOST, ???);
|
||||
// headers.put(Headers.REMOTE_USER, ???);
|
||||
|
@ -70,11 +81,11 @@ public class HttpSenderOverFCGI extends HttpSender
|
|||
// TODO: translate remaining HTTP header into the HTTP_* format
|
||||
|
||||
int request = getHttpChannel().getRequest();
|
||||
boolean noContent = !content.hasContent();
|
||||
boolean hasContent = content.hasContent();
|
||||
Generator.Result result = generator.generateRequestHeaders(request, headers,
|
||||
noContent ? new Callback.Adapter() : callback);
|
||||
hasContent ? callback : new Callback.Adapter());
|
||||
getHttpChannel().flush(result);
|
||||
if (noContent)
|
||||
if (!hasContent)
|
||||
{
|
||||
result = generator.generateRequestContent(request, null, true, callback);
|
||||
getHttpChannel().flush(result);
|
||||
|
|
Loading…
Reference in New Issue