Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
+ Changed variable from rfc7230 to rfc7239
+ Javadoc updates
  • Loading branch information
joakime committed Aug 25, 2016
1 parent d3f7256 commit 4c5d031
Showing 1 changed file with 33 additions and 36 deletions.
Expand Up @@ -38,12 +38,12 @@
* This customizer looks at at HTTP request for headers that indicate
* it has been forwarded by one or more proxies. Specifically handled are
* <ul>
* <li>Forwarded, as defined by <a href="https://tools.ietf.org/html/rfc7239">rfc7239</a>
* <li>X-Forwarded-Host</li>
* <li>X-Forwarded-Server</li>
* <li>X-Forwarded-For</li>
* <li>X-Forwarded-Proto</li>
* <li>X-Proxied-Https</li>
* <li>{@code Forwarded}, as defined by <a href="https://tools.ietf.org/html/rfc7239">rfc7239</a>
* <li>{@code X-Forwarded-Host}</li>
* <li>{@code X-Forwarded-Server}</li>
* <li>{@code X-Forwarded-For}</li>
* <li>{@code X-Forwarded-Proto}</li>
* <li>{@code X-Proxied-Https}</li>
* </ul>
* <p>If these headers are present, then the {@link Request} object is updated
* so that the proxy is not seen as the other end point of the connection on which
Expand All @@ -68,7 +68,7 @@ public class ForwardedRequestCustomizer implements Customizer

/**
* @return true if the proxy address obtained via
* X-Forwarded-Server or RFC7239 "by" is used as
* {@code X-Forwarded-Server} or RFC7239 "by" is used as
* the request authority. Default false
*/
public boolean getProxyAsAuthority()
Expand All @@ -78,7 +78,7 @@ public boolean getProxyAsAuthority()

/**
* @param proxyAsAuthority if true, use the proxy address obtained via
* X-Forwarded-Server or RFC7239 "by" as the request authority.
* {@code X-Forwarded-Server} or RFC7239 "by" as the request authority.
*/
public void setProxyAsAuthority(boolean proxyAsAuthority)
{
Expand All @@ -87,7 +87,7 @@ public void setProxyAsAuthority(boolean proxyAsAuthority)

/**
* Configure to only support the RFC7239 Forwarded header and to
* not support any X-Forwarded- headers. This convenience method
* not support any {@code X-Forwarded-} headers. This convenience method
* clears all the non RFC headers if passed true and sets them to
* the default values (if not already set) if passed false.
*/
Expand Down Expand Up @@ -159,7 +159,7 @@ public String getForwardedHostHeader()

/**
* @param forwardedHostHeader
* The header name for forwarded hosts (default x-forwarded-host)
* The header name for forwarded hosts (default {@code X-Forwarded-Host})
*/
public void setForwardedHostHeader(String forwardedHostHeader)
{
Expand All @@ -176,7 +176,7 @@ public String getForwardedServerHeader()

/**
* @param forwardedServerHeader
* The header name for forwarded server (default x-forwarded-server)
* The header name for forwarded server (default {@code X-Forwarded-Server})
*/
public void setForwardedServerHeader(String forwardedServerHeader)
{
Expand All @@ -193,7 +193,7 @@ public String getForwardedForHeader()

/**
* @param forwardedRemoteAddressHeader
* The header name for forwarded for (default x-forwarded-for)
* The header name for forwarded for (default {@code X-Forwarded-For})
*/
public void setForwardedForHeader(String forwardedRemoteAddressHeader)
{
Expand All @@ -203,7 +203,7 @@ public void setForwardedForHeader(String forwardedRemoteAddressHeader)
/**
* Get the forwardedProtoHeader.
*
* @return the forwardedProtoHeader (default X-Forwarded-For)
* @return the forwardedProtoHeader (default {@code X-Forwarded-Proto})
*/
public String getForwardedProtoHeader()
{
Expand All @@ -214,15 +214,15 @@ public String getForwardedProtoHeader()
* Set the forwardedProtoHeader.
*
* @param forwardedProtoHeader
* the forwardedProtoHeader to set (default X-Forwarded-For)
* the forwardedProtoHeader to set (default {@code X-Forwarded-Proto})
*/
public void setForwardedProtoHeader(String forwardedProtoHeader)
{
_forwardedProtoHeader = forwardedProtoHeader;
}

/**
* @return The header name holding a forwarded cipher suite (default Proxy-auth-cert)
* @return The header name holding a forwarded cipher suite (default {@code Proxy-auth-cert})
*/
public String getForwardedCipherSuiteHeader()
{
Expand All @@ -231,15 +231,15 @@ public String getForwardedCipherSuiteHeader()

/**
* @param forwardedCipherSuite
* The header name holding a forwarded cipher suite (default Proxy-auth-cert)
* The header name holding a forwarded cipher suite (default {@code Proxy-auth-cert})
*/
public void setForwardedCipherSuiteHeader(String forwardedCipherSuite)
{
_forwardedCipherSuiteHeader = forwardedCipherSuite;
}

/**
* @return The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)
* @return The header name holding a forwarded SSL Session ID (default {@code Proxy-ssl-id})
*/
public String getForwardedSslSessionIdHeader()
{
Expand All @@ -248,23 +248,23 @@ public String getForwardedSslSessionIdHeader()

/**
* @param forwardedSslSessionId
* The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)
* The header name holding a forwarded SSL Session ID (default {@code Proxy-ssl-id})
*/
public void setForwardedSslSessionIdHeader(String forwardedSslSessionId)
{
_forwardedSslSessionIdHeader = forwardedSslSessionId;
}

/**
* @return The header name holding a forwarded Https (on|off true|false) value
* @return The header name holding a forwarded Https status indicator (on|off true|false) (default {@code X-Proxied-Https})
*/
public String getForwardedHttpsHeader()
{
return _forwardedHttpsHeader;
}

/**
* @param forwardedHttpsHeader
* @param forwardedHttpsHeader the header name holding a forwarded Https status indicator(default {@code X-Proxied-Https})
*/
public void setForwardedHttpsHeader(String forwardedHttpsHeader)
{
Expand Down Expand Up @@ -294,7 +294,7 @@ public void customize(Connector connector, HttpConfiguration config, Request req
{
HttpFields httpFields = request.getHttpFields();

RFC7239 rfc7230 = null;
RFC7239 rfc7239 = null;
String forwardedHost = null;
String forwardedServer = null;
String forwardedFor = null;
Expand Down Expand Up @@ -343,9 +343,9 @@ public void customize(Connector connector, HttpConfiguration config, Request req

if (_forwardedHeader!=null && _forwardedHeader.equalsIgnoreCase(name))
{
if (rfc7230==null)
rfc7230= new RFC7239();
rfc7230.addValue(field.getValue());
if (rfc7239==null)
rfc7239= new RFC7239();
rfc7239.addValue(field.getValue());
}
}

Expand All @@ -356,9 +356,9 @@ public void customize(Connector connector, HttpConfiguration config, Request req
httpFields.put(_forcedHost);
request.setAuthority(_forcedHost.getHost(),_forcedHost.getPort());
}
else if (rfc7230!=null && rfc7230._host!=null)
else if (rfc7239!=null && rfc7239._host!=null)
{
HostPortHttpField auth = rfc7230._host;
HostPortHttpField auth = rfc7239._host;
httpFields.put(auth);
request.setAuthority(auth.getHost(),auth.getPort());
}
Expand All @@ -370,9 +370,9 @@ else if (forwardedHost != null)
}
else if (_proxyAsAuthority)
{
if (rfc7230!=null && rfc7230._by!=null)
if (rfc7239!=null && rfc7239._by!=null)
{
HostPortHttpField auth = rfc7230._by;
HostPortHttpField auth = rfc7239._by;
httpFields.put(auth);
request.setAuthority(auth.getHost(),auth.getPort());
}
Expand All @@ -383,20 +383,20 @@ else if (forwardedServer != null)
}

// handle remote end identifier
if (rfc7230!=null && rfc7230._for!=null)
if (rfc7239!=null && rfc7239._for!=null)
{
request.setRemoteAddr(InetSocketAddress.createUnresolved(rfc7230._for.getHost(),rfc7230._for.getPort()));
request.setRemoteAddr(InetSocketAddress.createUnresolved(rfc7239._for.getHost(),rfc7239._for.getPort()));
}
else if (forwardedFor != null)
{
request.setRemoteAddr(InetSocketAddress.createUnresolved(forwardedFor,request.getRemotePort()));
}

// handle protocol identifier
if (rfc7230!=null && rfc7230._proto!=null)
if (rfc7239!=null && rfc7239._proto!=null)
{
request.setScheme(rfc7230._proto);
if (rfc7230._proto.equals(config.getSecureScheme()))
request.setScheme(rfc7239._proto);
if (rfc7239._proto.equals(config.getSecureScheme()))
request.setSecure(true);
}
else if (forwardedProto != null)
Expand Down Expand Up @@ -455,9 +455,6 @@ public void setHostHeader(String hostHeader)
_forcedHost = new HostPortHttpField(hostHeader);
}

/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
/* ------------------------------------------------------------ */
private final class RFC7239 extends QuotedCSV
{
HostPortHttpField _by;
Expand Down

0 comments on commit 4c5d031

Please sign in to comment.