From aef2f42b5b7d542e843d6a739e48fbdc2722f77b Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 17 Jun 2014 22:12:49 +0200 Subject: [PATCH] FastCGI applications needs the Host header, which is missing in HTTP/2. --- .../java/org/eclipse/jetty/client/HttpClient.java | 2 +- .../jetty/fcgi/server/proxy/FastCGIProxyServlet.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java index 3486c811039..e636985b717 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpClient.java @@ -946,7 +946,7 @@ public class HttpClient extends ContainerLifeCycle return port > 0 ? port : HttpScheme.HTTPS.is(scheme) ? 443 : 80; } - protected boolean isDefaultPort(String scheme, int port) + public boolean isDefaultPort(String scheme, int port) { return HttpScheme.HTTPS.is(scheme) ? port == 443 : port == 80; } diff --git a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java index d107011752d..15c7d425520 100644 --- a/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java +++ b/jetty-fcgi/fcgi-server/src/main/java/org/eclipse/jetty/fcgi/server/proxy/FastCGIProxyServlet.java @@ -31,6 +31,7 @@ import org.eclipse.jetty.client.api.Request; import org.eclipse.jetty.fcgi.FCGI; import org.eclipse.jetty.fcgi.client.http.HttpClientTransportOverFCGI; import org.eclipse.jetty.http.HttpFields; +import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpScheme; import org.eclipse.jetty.proxy.AsyncProxyServlet; import org.eclipse.jetty.proxy.ProxyServlet; @@ -127,6 +128,16 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent proxyRequest.attribute(REQUEST_URI_ATTRIBUTE, originalURI); } + // If the Host header is missing, add it. + if (!proxyRequest.getHeaders().containsKey(HttpHeader.HOST.asString())) + { + String host = request.getServerName(); + int port = request.getServerPort(); + if (!getHttpClient().isDefaultPort(request.getScheme(), port)) + host += ":" + port; + proxyRequest.header(HttpHeader.HOST, host); + } + super.customizeProxyRequest(proxyRequest, request); }