From 0c29968ee2ea43664f7157ef7cc4f3654192f411 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 3 Oct 2013 00:54:29 +0200 Subject: [PATCH 1/2] Improved the Flusher. --- .../eclipse/jetty/fcgi/generator/Flusher.java | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/fcgi-core/src/main/java/org/eclipse/jetty/fcgi/generator/Flusher.java b/fcgi-core/src/main/java/org/eclipse/jetty/fcgi/generator/Flusher.java index 8fd8b7252be..ae262d7afaf 100644 --- a/fcgi-core/src/main/java/org/eclipse/jetty/fcgi/generator/Flusher.java +++ b/fcgi-core/src/main/java/org/eclipse/jetty/fcgi/generator/Flusher.java @@ -36,7 +36,6 @@ public class Flusher private final Queue 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 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); } } From 1cb3649b7e1c50b4226db9a76feeb57a399d0d1f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 3 Oct 2013 00:55:52 +0200 Subject: [PATCH 2/2] Added URI regexp functionality to be able to split the URIs into the CGI variables. --- .../http/HttpClientTransportOverFCGI.java | 16 +++++++++++++--- .../fcgi/client/http/HttpSenderOverFCGI.java | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpClientTransportOverFCGI.java b/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpClientTransportOverFCGI.java index 1a921dcef5d..cbbbee4c506 100644 --- a/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpClientTransportOverFCGI.java +++ b/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpClientTransportOverFCGI.java @@ -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 diff --git a/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpSenderOverFCGI.java b/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpSenderOverFCGI.java index b1a715117c3..3e8fce96a29 100644 --- a/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpSenderOverFCGI.java +++ b/fcgi-http-client-transport/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpSenderOverFCGI.java @@ -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);