Class FastCGIProxyHandler

All Implemented Interfaces:
Handler, Request.Handler, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Invocable

public class FastCGIProxyHandler extends ProxyHandler.Reverse

Specific implementation of ProxyHandler.Reverse for FastCGI.

This handler accepts an HTTP request and transforms it into a FastCGI request that is sent to the FastCGI server, and viceversa for the response.

See Also:
  • Constructor Details

    • FastCGIProxyHandler

      public FastCGIProxyHandler(String uriPattern, String uriReplacement, String scriptRoot)

      Creates a new instance that rewrites the HttpURI with the given pattern and replacement strings, using String.replaceAll(String, String).

      Parameters:
      uriPattern - the regex pattern to use to match the incoming URI
      uriReplacement - the replacement string to use to rewrite the incoming URI
      scriptRoot - the root directory path of the FastCGI files
      See Also:
    • FastCGIProxyHandler

      public FastCGIProxyHandler(Function<Request,HttpURI> httpURIRewriter, String scriptRoot)

      Creates a new instance with the given HttpURI rewriter function.

      The HttpURI rewriter function should return the URI of the FastCGI server.

      The scriptRoot path must be set to the directory where the application that must be served via FastCGI is installed and corresponds to the FastCGI DOCUMENT_ROOT parameter.

      Parameters:
      httpURIRewriter - a function that returns the URI of the FastCGI server
      scriptRoot - the root directory path of the FastCGI files
  • Method Details

    • getScriptRoot

      public String getScriptRoot()
      Get the root directory path of the FastCGI files.
      Returns:
      the root directory path of the FastCGI files
    • getScriptPattern

      public Pattern getScriptPattern()
      Returns:
      the regular expression that extracts the SCRIPT_NAME and the PATH_INFO FastCGI parameters
    • setScriptPattern

      public void setScriptPattern(Pattern scriptPattern)

      Sets a regular expression with at least 1 and at most 2 groups that specify respectively:

      • the FastCGI SCRIPT_NAME parameter
      • the FastCGI PATH_INFO parameter
      Parameters:
      scriptPattern - the regular expression that extracts the SCRIPT_NAME and the PATH_INFO FastCGI parameters
    • getOriginalPathAttribute

      public String getOriginalPathAttribute()
      Returns:
      the attribute name of the original client-to-proxy request path
    • setOriginalPathAttribute

      public void setOriginalPathAttribute(String originalPathAttribute)

      Sets the client-to-proxy request attribute name to use to retrieve the original request path.

      For example, the request URI may be rewritten by a previous handler that might save the original request path in a request attribute.

      Parameters:
      originalPathAttribute - the attribute name of the original client-to-proxy request path
    • getOriginalQueryAttribute

      public String getOriginalQueryAttribute()
      Returns:
      the attribute name of the original client-to-proxy request query
    • setOriginalQueryAttribute

      public void setOriginalQueryAttribute(String originalQueryAttribute)

      Sets the client-to-proxy request attribute name to use to retrieve the original request query.

      For example, the request URI may be rewritten by a previous handler that might save the original request query in a request attribute.

      Parameters:
      originalQueryAttribute - the attribute name of the original client-to-proxy request query
    • isFastCGISecure

      public boolean isFastCGISecure()
      Returns:
      whether to forward the HTTPS FastCGI parameter in the FastCGI request
    • setFastCGISecure

      public void setFastCGISecure(boolean fcgiSecure)

      Sets whether to forward the HTTPS FastCGI parameter in the FastCGI request to the FastCGI server.

      Parameters:
      fcgiSecure - whether to forward the HTTPS FastCGI parameter in the FastCGI request
    • getFastCGIEnvNames

      public Set<String> getFastCGIEnvNames()
      Returns:
      the names of the environment variables forwarded in the FastCGI request
    • setFastCGIEnvNames

      public void setFastCGIEnvNames(Set<String> fcgiEnvNames)

      Sets the names of environment variables that will forwarded, along with their value retrieved via System.getenv(String), in the FastCGI request to the FastCGI server.

      Parameters:
      fcgiEnvNames - the names of the environment variables forwarded in the FastCGI request
      See Also:
    • getUnixDomainPath

      public Path getUnixDomainPath()
      Returns:
      the Unix-Domain path the FastCGI server listens to, or null if the FastCGI server listens over network
    • setUnixDomainPath

      public void setUnixDomainPath(Path unixDomainPath)

      Sets the Unix-Domain path the FastCGI server listens to.

      If the FastCGI server listens over the network (not over a Unix-Domain path), then the FastCGI server host and port must be specified by the HttpURI rewrite function passed to the constructor.

      Parameters:
      unixDomainPath - the Unix-Domain path the FastCGI server listens to
    • doStart

      protected void doStart() throws Exception
      Description copied from class: ContainerLifeCycle
      Starts the managed lifecycle beans in the order they were added.
      Overrides:
      doStart in class ProxyHandler
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • newHttpClient

      protected HttpClient newHttpClient()
      Description copied from class: ProxyHandler

      Creates a new HttpClient instance, by default with a thread pool named proxy-client and with the dynamic transport configured only with HTTP/1.1.

      Overrides:
      newHttpClient in class ProxyHandler
      Returns:
      a new HttpClient instance
    • sendProxyToServerRequest

      protected void sendProxyToServerRequest(Request clientToProxyRequest, Request proxyToServerRequest, Response proxyToClientResponse, Callback proxyToClientCallback)
      Overrides:
      sendProxyToServerRequest in class ProxyHandler
    • customizeFastCGIHeaders

      protected void customizeFastCGIHeaders(Request proxyToServerRequest, HttpFields.Mutable fastCGIHeaders)