Top Description Inners Fields Constructors Methods
org.eclipse.jetty.server

public Class ForwardedRequestCustomizer

extends Object
implements Customizer
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.server.HttpConfiguration.Customizer
Imports
java.lang.invoke.MethodHandle, .MethodHandles, .MethodType, java.net.InetSocketAddress, .SocketAddress, java.util.Set, org.eclipse.jetty.http.BadMessageException, .HostPortHttpField, .HttpField, .HttpFields, .HttpHeader, .HttpScheme, .HttpURI, .QuotedCSVParser, org.eclipse.jetty.io.EndPoint, org.eclipse.jetty.server.internal.HttpConnection, org.eclipse.jetty.util.Attributes, .HostPort, .Index, .StringUtil, .TypeUtil, org.slf4j.Logger, .LoggerFactory

Customize Requests for Proxy Forwarding.

This customizer looks at at HTTP request for headers that indicate it has been forwarded by one or more proxies. Specifically handled are

If these headers are present, then the Request object is wrapped so that the proxy is not seen as the other end point of the connection on which the request came

Headers can also be defined so that forwarded SSL Session IDs and Cipher suites may be customised

The Authority (host and port) is updated on the Request object based on the host / port information in the following search order.

Request Authority Search Order
# Value Origin Host Port Protocol Notes
1 Forwarded Header "host=<host>" param (Required) "host=<host>:<port> param (Implied) "proto=<value>" param (Optional) From left-most relevant parameter (see rfc7239)
2 X-Forwarded-Host Header Required Implied n/a left-most value
3 X-Forwarded-Port Header n/a Required n/a left-most value (only if getForwardedPortAsAuthority() is true)
4 X-Forwarded-Server Header Required Optional n/a left-most value
5 X-Forwarded-Proto Header n/a Implied from value Required

left-most value becomes protocol.

6 X-Proxied-Https Header n/a Implied from value boolean

left-most value determines protocol and port.

See Also
Wikipedia: X-Forwarded-For, RFC 7239: Forwarded HTTP Extension

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class
public static enum

Field Summary

Modifier and TypeField and Description
private HostPortHttpField
private String
private String
private String
private String
private String
private boolean
private String
private String
private String
private String
private final Index.Mutable<MethodHandle>
private boolean
private boolean
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Request
public String
public String
getForwardedCipherSuiteHeader()

Returns: The header name holding a forwarded cipher suite (default Proxy-auth-cert)

public String

Returns:

the forwarded for header
getForwardedForHeader
()

Get the forwarded for header.

public String
getForwardedHeader()

Returns: The header name for RFC forwarded (default Forwarded)

public String
public String
getForwardedHttpsHeader()

Returns: The header name holding a forwarded Https status indicator (on|off true|false) (default X-Proxied-Https)

public boolean
getForwardedPortAsAuthority()

Returns: if true, the X-Forwarded-Port header applies to the authority, else it applies to the remote client address

public String
public String

Returns:

the forwardedProtoHeader (default X-Forwarded-Proto)
getForwardedProtoHeader
()

Get the forwardedProtoHeader.

public String

Returns:

the header name for forwarded server.
getForwardedServerHeader
()

Get the header name for forwarded server..

public String
getForwardedSslSessionIdHeader()

Returns: The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)

public String
protected static String
getLeftMost(String headerValue)

public boolean
getProxyAsAuthority()

Returns: true if the proxy address obtained via X-Forwarded-Server or RFC7239 "by" is used as the request authority.

protected static int
public boolean
isSslIsSecure()

Returns: true if the presence of an SSL session or certificate header is sufficient to indicate a secure request (default is true)

protected void
public void
setForcedHost(String
The value of the host header to force.
hostAndPort
)

Set a forced valued for the host header.

public void
setForwardedCipherSuiteHeader(String
The header name holding a forwarded cipher suite (default Proxy-auth-cert)
forwardedCipherSuiteHeader
)

public void
setForwardedForHeader(String
The header name for forwarded for (default X-Forwarded-For)
forwardedRemoteAddressHeader
)

public void
setForwardedHeader(String
The header name for RFC forwarded (default Forwarded)
forwardedHeader
)

public void
setForwardedHostHeader(String
The header name for forwarded hosts (default X-Forwarded-Host)
forwardedHostHeader
)

public void
setForwardedHttpsHeader(String
the header name holding a forwarded Https status indicator(default X-Proxied-Https)
forwardedHttpsHeader
)

Set the header name holding a forwarded Https status indicator(default X-Proxied-Https).

public void
setForwardedOnly(boolean
Configure to only support the RFC7239 Forwarded header and to not support any 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.
rfc7239only
)

public void
setForwardedPortAsAuthority(boolean
if true, the X-Forwarded-Port header applies to the authority, else it applies to the remote client address
forwardedPortAsAuthority
)

Set if the X-Forwarded-Port header will be used for Authority

public void
setForwardedPortHeader(String
The header name for forwarded hosts (default X-Forwarded-Port)
forwardedPortHeader
)

public void
setForwardedProtoHeader(String
the forwardedProtoHeader to set (default X-Forwarded-Proto)
forwardedProtoHeader
)

Set the forwardedProtoHeader.

public void
setForwardedServerHeader(String
The header name for forwarded server (default X-Forwarded-Server)
forwardedServerHeader
)

public void
setForwardedSslSessionIdHeader(String
The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)
forwardedSslSessionIdHeader
)

public void
setHostHeader(String
The value of the host header to force.
hostHeader
)

Set a forced valued for the host header.

public void
setProxyAsAuthority(boolean
if true, use the proxy address obtained via X-Forwarded-Server or RFC7239 "by" as the request authority.
proxyAsAuthority
)

public void
setSslIsSecure(boolean
true if the presence of an SSL session or certificate header is sufficient to indicate a secure request (default is true)
sslIsSecure
)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
updateForwardedHandle(MethodHandles.Lookup lookup, String headerName, String forwardedMethodName)

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_forcedHostback to summary
private HostPortHttpField _forcedHost
_forwardedCipherSuiteHeaderback to summary
private String _forwardedCipherSuiteHeader
_forwardedForHeaderback to summary
private String _forwardedForHeader
_forwardedHeaderback to summary
private String _forwardedHeader
_forwardedHostHeaderback to summary
private String _forwardedHostHeader
_forwardedHttpsHeaderback to summary
private String _forwardedHttpsHeader
_forwardedPortAsAuthorityback to summary
private boolean _forwardedPortAsAuthority
_forwardedPortHeaderback to summary
private String _forwardedPortHeader
_forwardedProtoHeaderback to summary
private String _forwardedProtoHeader
_forwardedServerHeaderback to summary
private String _forwardedServerHeader
_forwardedSslSessionIdHeaderback to summary
private String _forwardedSslSessionIdHeader
_handlesback to summary
private final Index.Mutable<MethodHandle> _handles
_proxyAsAuthorityback to summary
private boolean _proxyAsAuthority
_sslIsSecureback to summary
private boolean _sslIsSecure
LOGback to summary
private static final Logger LOG

Constructor Detail

ForwardedRequestCustomizerback to summary
public ForwardedRequestCustomizer()

Method Detail

customizeback to summary
public Request customize(Request request, HttpFields.Mutable responseHeaders)

Implements org.eclipse.jetty.server.HttpConfiguration.Customizer.customize.

Annotations
@Override
getForcedHostback to summary
public String getForcedHost()
getForwardedCipherSuiteHeaderback to summary
public String getForwardedCipherSuiteHeader()
Returns:String

The header name holding a forwarded cipher suite (default Proxy-auth-cert)

getForwardedForHeaderback to summary
public String getForwardedForHeader()

Get the forwarded for header.

Returns:String

the forwarded for header

getForwardedHeaderback to summary
public String getForwardedHeader()
Returns:String

The header name for RFC forwarded (default Forwarded)

getForwardedHostHeaderback to summary
public String getForwardedHostHeader()
getForwardedHttpsHeaderback to summary
public String getForwardedHttpsHeader()
Returns:String

The header name holding a forwarded Https status indicator (on|off true|false) (default X-Proxied-Https)

getForwardedPortAsAuthorityback to summary
public boolean getForwardedPortAsAuthority()
Returns:boolean

if true, the X-Forwarded-Port header applies to the authority, else it applies to the remote client address

getForwardedPortHeaderback to summary
public String getForwardedPortHeader()
getForwardedProtoHeaderback to summary
public String getForwardedProtoHeader()

Get the forwardedProtoHeader.

Returns:String

the forwardedProtoHeader (default X-Forwarded-Proto)

getForwardedServerHeaderback to summary
public String getForwardedServerHeader()

Get the header name for forwarded server..

Returns:String

the header name for forwarded server.

getForwardedSslSessionIdHeaderback to summary
public String getForwardedSslSessionIdHeader()
Returns:String

The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)

getHostHeaderback to summary
public String getHostHeader()
getLeftMostback to summary
protected static String getLeftMost(String headerValue)
getProxyAsAuthorityback to summary
public boolean getProxyAsAuthority()
Returns:boolean

true if the proxy address obtained via X-Forwarded-Server or RFC7239 "by" is used as the request authority. Default false

getSecurePortback to summary
protected static int getSecurePort(HttpConfiguration config)
isSslIsSecureback to summary
public boolean isSslIsSecure()
Returns:boolean

true if the presence of an SSL session or certificate header is sufficient to indicate a secure request (default is true)

onErrorback to summary
protected void onError(HttpField field, Throwable t)
setForcedHostback to summary
public void setForcedHost(String hostAndPort)

Set a forced valued for the host header.

Parameters
hostAndPort:String

The value of the host header to force.

setForwardedCipherSuiteHeaderback to summary
public void setForwardedCipherSuiteHeader(String forwardedCipherSuiteHeader)
Parameters
forwardedCipherSuiteHeader:String

The header name holding a forwarded cipher suite (default Proxy-auth-cert)

setForwardedForHeaderback to summary
public void setForwardedForHeader(String forwardedRemoteAddressHeader)
Parameters
forwardedRemoteAddressHeader:String

The header name for forwarded for (default X-Forwarded-For)

setForwardedHeaderback to summary
public void setForwardedHeader(String forwardedHeader)
Parameters
forwardedHeader:String

The header name for RFC forwarded (default Forwarded)

setForwardedHostHeaderback to summary
public void setForwardedHostHeader(String forwardedHostHeader)
Parameters
forwardedHostHeader:String

The header name for forwarded hosts (default X-Forwarded-Host)

setForwardedHttpsHeaderback to summary
public void setForwardedHttpsHeader(String forwardedHttpsHeader)

Set the header name holding a forwarded Https status indicator(default X-Proxied-Https).

Parameters
forwardedHttpsHeader:String

the header name holding a forwarded Https status indicator(default X-Proxied-Https)

setForwardedOnlyback to summary
public void setForwardedOnly(boolean rfc7239only)
Parameters
rfc7239only:boolean

Configure to only support the RFC7239 Forwarded header and to not support any 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.

setForwardedPortAsAuthorityback to summary
public void setForwardedPortAsAuthority(boolean forwardedPortAsAuthority)

Set if the X-Forwarded-Port header will be used for Authority

Parameters
forwardedPortAsAuthority:boolean

if true, the X-Forwarded-Port header applies to the authority, else it applies to the remote client address

setForwardedPortHeaderback to summary
public void setForwardedPortHeader(String forwardedPortHeader)
Parameters
forwardedPortHeader:String

The header name for forwarded hosts (default X-Forwarded-Port)

setForwardedProtoHeaderback to summary
public void setForwardedProtoHeader(String forwardedProtoHeader)

Set the forwardedProtoHeader.

Parameters
forwardedProtoHeader:String

the forwardedProtoHeader to set (default X-Forwarded-Proto)

setForwardedServerHeaderback to summary
public void setForwardedServerHeader(String forwardedServerHeader)
Parameters
forwardedServerHeader:String

The header name for forwarded server (default X-Forwarded-Server)

setForwardedSslSessionIdHeaderback to summary
public void setForwardedSslSessionIdHeader(String forwardedSslSessionIdHeader)
Parameters
forwardedSslSessionIdHeader:String

The header name holding a forwarded SSL Session ID (default Proxy-ssl-id)

setHostHeaderback to summary
public void setHostHeader(String hostHeader)

Set a forced valued for the host header.

Parameters
hostHeader:String

The value of the host header to force.

setProxyAsAuthorityback to summary
public void setProxyAsAuthority(boolean proxyAsAuthority)
Parameters
proxyAsAuthority:boolean

if true, use the proxy address obtained via X-Forwarded-Server or RFC7239 "by" as the request authority.

setSslIsSecureback to summary
public void setSslIsSecure(boolean sslIsSecure)
Parameters
sslIsSecure:boolean

true if the presence of an SSL session or certificate header is sufficient to indicate a secure request (default is true)

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateForwardedHandleback to summary
private void updateForwardedHandle(MethodHandles.Lookup lookup, String headerName, String forwardedMethodName) throws NoSuchMethodException, IllegalAccessException
updateHandlesback to summary
private void updateHandles()
org.eclipse.jetty.server back to summary

private Class ForwardedRequestCustomizer.Forwarded

extends QuotedCSVParser
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ForwardedRequestCustomizer.MutableHostPort
pack-priv HttpConfiguration
pack-priv ForwardedRequestCustomizer.MutableHostPort
pack-priv String
pack-priv ForwardedRequestCustomizer.Source
pack-priv Request
pack-priv Boolean
pack-priv boolean
pack-priv EndPoint.SslSessionData
Inherited from org.eclipse.jetty.http.QuotedCSVParser:
_keepQuotesDELIMITERSLIST_TOKENIZER

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private ForwardedRequestCustomizer.MutableHostPort
private ForwardedRequestCustomizer.MutableHostPort
public void
handleCipherSuite(HttpField field)

Called if header is Proxy-auth-cert

public void
handleForwardedFor(HttpField field)

Called if header is X-Forwarded-For

public void
handleForwardedHost(HttpField field)

Called if header is X-Forwarded-Host

public void
handleForwardedPort(HttpField field)

Called if header is X-Forwarded-Port

public void
handleForwardedServer(HttpField field)

Called if header is X-Forwarded-Server

public void
handleHttps(HttpField field)

Called if header is X-Proxied-Https

public void
handleProto(HttpField field)

Called if header is X-Forwarded-Proto

public void
handleRFC7239(HttpField field)

Called if header is Forwarded

public void
handleSslSessionId(HttpField field)

Called if header is Proxy-Ssl-Id

public boolean
public boolean
protected void
parsedParam(StringBuffer
Containing the trimmed value and all parameters, which may be mutated
buffer
,
int
The length of the value
valueLength
,
int
The index of the start of the parameter just parsed
paramName
,
int
The index of the start of the parameter value just parsed, or -1
paramValue
)

Overrides org.eclipse.jetty.http.QuotedCSVParser.parsedParam.

Called when a parameter has been parsed

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
private void
private void
Inherited from org.eclipse.jetty.http.QuotedCSVParser:
addValueparsedValueparsedValueAndParamsquotequoteIfNeededunquote

Field Detail

_authorityback to summary
pack-priv ForwardedRequestCustomizer.MutableHostPort _authority
_configback to summary
pack-priv HttpConfiguration _config
_forback to summary
pack-priv ForwardedRequestCustomizer.MutableHostPort _for
_protoback to summary
pack-priv String _proto
_protoSourceback to summary
pack-priv ForwardedRequestCustomizer.Source _protoSource
_requestback to summary
pack-priv Request _request
_secureback to summary
pack-priv Boolean _secure
_secureSchemeback to summary
pack-priv boolean _secureScheme
_sslSessionDataback to summary
pack-priv EndPoint.SslSessionData _sslSessionData

Constructor Detail

Forwardedback to summary
public Forwarded(Request request, HttpConfiguration config)

Method Detail

getAuthorityback to summary
private ForwardedRequestCustomizer.MutableHostPort getAuthority()
getForback to summary
private ForwardedRequestCustomizer.MutableHostPort getFor()
handleCipherSuiteback to summary
public void handleCipherSuite(HttpField field)

Called if header is Proxy-auth-cert

handleForwardedForback to summary
public void handleForwardedFor(HttpField field)

Called if header is X-Forwarded-For

handleForwardedHostback to summary
public void handleForwardedHost(HttpField field)

Called if header is X-Forwarded-Host

handleForwardedPortback to summary
public void handleForwardedPort(HttpField field)

Called if header is X-Forwarded-Port

handleForwardedServerback to summary
public void handleForwardedServer(HttpField field)

Called if header is X-Forwarded-Server

handleHttpsback to summary
public void handleHttps(HttpField field)

Called if header is X-Proxied-Https

handleProtoback to summary
public void handleProto(HttpField field)

Called if header is X-Forwarded-Proto

handleRFC7239back to summary
public void handleRFC7239(HttpField field)

Called if header is Forwarded

handleSslSessionIdback to summary
public void handleSslSessionId(HttpField field)

Called if header is Proxy-Ssl-Id

hasForback to summary
public boolean hasFor()
isSecureback to summary
public boolean isSecure()
parsedParamback to summary
protected void parsedParam(StringBuffer buffer, int valueLength, int paramName, int paramValue)

Overrides org.eclipse.jetty.http.QuotedCSVParser.parsedParam.

Doc from org.eclipse.jetty.http.QuotedCSVParser.parsedParam.

Called when a parameter has been parsed

Parameters
buffer:StringBuffer

Containing the trimmed value and all parameters, which may be mutated

valueLength:int

The length of the value

paramName:int

The index of the start of the parameter just parsed

paramValue:int

The index of the start of the parameter value just parsed, or -1

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateAuthorityback to summary
private void updateAuthority(String value, ForwardedRequestCustomizer.Source source)
updatePortback to summary
private void updatePort(int port, ForwardedRequestCustomizer.Source source)
updateProtoback to summary
private void updateProto(String proto, ForwardedRequestCustomizer.Source source)
org.eclipse.jetty.server back to summary

private Class ForwardedRequestCustomizer.MutableHostPort

extends Object
Class Inheritance
  • java.lang.Object
  • org.eclipse.jetty.server.ForwardedRequestCustomizer.MutableHostPort

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv ForwardedRequestCustomizer.Source
pack-priv int
pack-priv ForwardedRequestCustomizer.Source
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_hostback to summary
pack-priv String _host
_hostSourceback to summary
pack-priv ForwardedRequestCustomizer.Source _hostSource
_portback to summary
pack-priv int _port
_portSourceback to summary
pack-priv ForwardedRequestCustomizer.Source _portSource
IMPLIEDback to summary
public static final int IMPLIED
UNSETback to summary
public static final int UNSET

Constructor Detail

MutableHostPortback to summary
private MutableHostPort()

Method Detail

setHostback to summary
public void setHost(String host, ForwardedRequestCustomizer.Source source)
setHostPortback to summary
public void setHostPort(String host, int port, ForwardedRequestCustomizer.Source source)
setHostPortback to summary
public void setHostPort(HostPort hostPort, ForwardedRequestCustomizer.Source source)
setPortback to summary
public void setPort(int port, ForwardedRequestCustomizer.Source source)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.eclipse.jetty.server back to summary

public final Enum ForwardedRequestCustomizer.Source

extends Enum<ForwardedRequestCustomizer.Source>
Class Inheritance

Ordered Source Enum.

Lowest first, Last/Highest priority wins

Field Summary

Modifier and TypeField and Description
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source
public static final ForwardedRequestCustomizer.Source

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv int
public static ForwardedRequestCustomizer.Source
public static ForwardedRequestCustomizer.Source[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

FORCEDback to summary
public static final ForwardedRequestCustomizer.Source FORCED
FORWARDEDback to summary
public static final ForwardedRequestCustomizer.Source FORWARDED
UNSETback to summary
public static final ForwardedRequestCustomizer.Source UNSET
XFORWARDED_FORback to summary
public static final ForwardedRequestCustomizer.Source XFORWARDED_FOR
XFORWARDED_HOSTback to summary
public static final ForwardedRequestCustomizer.Source XFORWARDED_HOST
XFORWARDED_PORTback to summary
public static final ForwardedRequestCustomizer.Source XFORWARDED_PORT
XFORWARDED_PROTOback to summary
public static final ForwardedRequestCustomizer.Source XFORWARDED_PROTO
XFORWARDED_SERVERback to summary
public static final ForwardedRequestCustomizer.Source XFORWARDED_SERVER
XPROXIED_HTTPSback to summary
public static final ForwardedRequestCustomizer.Source XPROXIED_HTTPS

Constructor Detail

Sourceback to summary
private Source()

Method Detail

priorityback to summary
pack-priv int priority()
valueOfback to summary
public static ForwardedRequestCustomizer.Source valueOf(String name)
valuesback to summary
public static ForwardedRequestCustomizer.Source[] values()