Merge pull request #4738 from eclipse/jetty-9.4.x-4735-env_variables_fcgi
Fixes #4735 - Get env variables in PHP scripts served through FastCGI…
This commit is contained in:
commit
f79b5aa507
|
@ -14,9 +14,22 @@
|
||||||
<bundle-symbolic-name>${project.groupId}.server</bundle-symbolic-name>
|
<bundle-symbolic-name>${project.groupId}.server</bundle-symbolic-name>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<profiles>
|
||||||
<plugins></plugins>
|
<profile>
|
||||||
</build>
|
<id>jdk9</id>
|
||||||
|
<activation>
|
||||||
|
<jdk>[9,)</jdk>
|
||||||
|
</activation>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
|
<artifactId>jetty-alpn-java-server</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -38,6 +51,7 @@
|
||||||
<artifactId>jetty-server</artifactId>
|
<artifactId>jetty-server</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-servlet</artifactId>
|
<artifactId>jetty-servlet</artifactId>
|
||||||
|
@ -52,7 +66,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.jetty</groupId>
|
<groupId>org.eclipse.jetty</groupId>
|
||||||
<artifactId>jetty-alpn-server</artifactId>
|
<artifactId>jetty-alpn-openjdk8-server</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -19,11 +19,14 @@
|
||||||
package org.eclipse.jetty.fcgi.server.proxy;
|
package org.eclipse.jetty.fcgi.server.proxy;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletConfig;
|
import javax.servlet.ServletConfig;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -48,7 +51,7 @@ import org.eclipse.jetty.util.ProcessorUtils;
|
||||||
* that is sent to the FastCGI server specified in the {@code proxyTo}
|
* that is sent to the FastCGI server specified in the {@code proxyTo}
|
||||||
* init-param.
|
* init-param.
|
||||||
* <p>
|
* <p>
|
||||||
* This servlet accepts two additional init-params:
|
* This servlet accepts these additional {@code init-param}s:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@code scriptRoot}, mandatory, that must be set to the directory where
|
* <li>{@code scriptRoot}, mandatory, that must be set to the directory where
|
||||||
* the application that must be served via FastCGI is installed and corresponds to
|
* the application that must be served via FastCGI is installed and corresponds to
|
||||||
|
@ -62,6 +65,8 @@ import org.eclipse.jetty.util.ProcessorUtils;
|
||||||
* </ul></li>
|
* </ul></li>
|
||||||
* <li>{@code fastCGI.HTTPS}, optional, defaults to false, that specifies whether
|
* <li>{@code fastCGI.HTTPS}, optional, defaults to false, that specifies whether
|
||||||
* to force the FastCGI {@code HTTPS} parameter to the value {@code on}</li>
|
* to force the FastCGI {@code HTTPS} parameter to the value {@code on}</li>
|
||||||
|
* <li>{@code fastCGI.envNames}, optional, a comma separated list of environment variable
|
||||||
|
* names read via {@link System#getenv(String)} that are forwarded as FastCGI parameters.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @see TryFilesFilter
|
* @see TryFilesFilter
|
||||||
|
@ -73,6 +78,7 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
|
||||||
public static final String ORIGINAL_URI_ATTRIBUTE_INIT_PARAM = "originalURIAttribute";
|
public static final String ORIGINAL_URI_ATTRIBUTE_INIT_PARAM = "originalURIAttribute";
|
||||||
public static final String ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM = "originalQueryAttribute";
|
public static final String ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM = "originalQueryAttribute";
|
||||||
public static final String FASTCGI_HTTPS_INIT_PARAM = "fastCGI.HTTPS";
|
public static final String FASTCGI_HTTPS_INIT_PARAM = "fastCGI.HTTPS";
|
||||||
|
public static final String FASTCGI_ENV_NAMES_INIT_PARAM = "fastCGI.envNames";
|
||||||
|
|
||||||
private static final String REMOTE_ADDR_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remoteAddr";
|
private static final String REMOTE_ADDR_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remoteAddr";
|
||||||
private static final String REMOTE_PORT_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remotePort";
|
private static final String REMOTE_PORT_ATTRIBUTE = FastCGIProxyServlet.class.getName() + ".remotePort";
|
||||||
|
@ -87,6 +93,7 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
|
||||||
private String originalURIAttribute;
|
private String originalURIAttribute;
|
||||||
private String originalQueryAttribute;
|
private String originalQueryAttribute;
|
||||||
private boolean fcgiHTTPS;
|
private boolean fcgiHTTPS;
|
||||||
|
private Set<String> fcgiEnvNames;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws ServletException
|
public void init() throws ServletException
|
||||||
|
@ -102,6 +109,15 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
|
||||||
originalQueryAttribute = getInitParameter(ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM);
|
originalQueryAttribute = getInitParameter(ORIGINAL_QUERY_ATTRIBUTE_INIT_PARAM);
|
||||||
|
|
||||||
fcgiHTTPS = Boolean.parseBoolean(getInitParameter(FASTCGI_HTTPS_INIT_PARAM));
|
fcgiHTTPS = Boolean.parseBoolean(getInitParameter(FASTCGI_HTTPS_INIT_PARAM));
|
||||||
|
|
||||||
|
fcgiEnvNames = Collections.emptySet();
|
||||||
|
String envNames = getInitParameter(FASTCGI_ENV_NAMES_INIT_PARAM);
|
||||||
|
if (envNames != null)
|
||||||
|
{
|
||||||
|
fcgiEnvNames = Stream.of(envNames.split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,6 +211,13 @@ public class FastCGIProxyServlet extends AsyncProxyServlet.Transparent
|
||||||
|
|
||||||
protected void customizeFastCGIHeaders(Request proxyRequest, HttpFields fastCGIHeaders)
|
protected void customizeFastCGIHeaders(Request proxyRequest, HttpFields fastCGIHeaders)
|
||||||
{
|
{
|
||||||
|
for (String envName : fcgiEnvNames)
|
||||||
|
{
|
||||||
|
String envValue = System.getenv(envName);
|
||||||
|
if (envValue != null)
|
||||||
|
fastCGIHeaders.put(envName, envValue);
|
||||||
|
}
|
||||||
|
|
||||||
fastCGIHeaders.remove("HTTP_PROXY");
|
fastCGIHeaders.remove("HTTP_PROXY");
|
||||||
|
|
||||||
fastCGIHeaders.put(FCGI.Headers.REMOTE_ADDR, (String)proxyRequest.getAttributes().get(REMOTE_ADDR_ATTRIBUTE));
|
fastCGIHeaders.put(FCGI.Headers.REMOTE_ADDR, (String)proxyRequest.getAttributes().get(REMOTE_ADDR_ATTRIBUTE));
|
||||||
|
|
Loading…
Reference in New Issue