Class ForwardedRequest
- All Implemented Interfaces:
HttpRequestInterceptor
The Forwarded header consists of a list of key-value pairs separated by semicolons. The keys that can be used in the Forwarded header include "host", "port", "proto", "for", and "by". The host key is used to specify the host name or IP address of the request authority. The port key is used to specify the port number of the request authority. The proto key is used to specify the protocol version of the request. The for key is used to specify the IP address of the client making the request. The by key is used to specify the IP address of the node adding the Forwarded header.
When multiple proxy servers are involved in forwarding a request, each proxy can add its own Forwarded header to the request. This allows for the capture of information about each intermediate node that the request passes through.
The ForwardedRequest class adds the Forwarded header to the request by implementing the process()
method of the HttpRequestInterceptor interface. The method retrieves the ProtocolVersion and
URIAuthority from the HttpContext. The ProtocolVersion is used to determine the
proto key value and the URIAuthority is used to determine the host and port key values.
The method also retrieves the EndpointDetails from the HttpContext, if it exists.
The EndpointDetails is used to determine the by and for key values. If a Forwarded header
already exists in the request, the existing header is not overwritten; instead, the new header
value is appended to the existing header value, with a comma separator.
- Since:
- 5.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringThe name of the header to set in the HTTP request.static final HttpRequestInterceptorSingleton instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprocess(HttpRequest request, EntityDetails entity, HttpContext localContext) The process method adds a Forwarded header to an HTTP request containing information about the intermediate nodes that the request has passed through.
-
Field Details
-
FORWARDED_HEADER_NAME
The name of the header to set in the HTTP request.- See Also:
-
INSTANCE
Singleton instance.
-
-
Constructor Details
-
ForwardedRequest
public ForwardedRequest()
-
-
Method Details
-
process
public void process(HttpRequest request, EntityDetails entity, HttpContext localContext) throws HttpException, IOException The process method adds a Forwarded header to an HTTP request containing information about the intermediate nodes that the request has passed through. If a Forwarded header already exists in the request, the new header value is appended to the existing header value, with a comma separator.The method retrieves the
ProtocolVersionandURIAuthorityfrom the HttpContext. The ProtocolVersion is used to determine the proto key value and the URIAuthority is used to determine the host and port key values. The method also retrieves the EndpointDetails from theHttpContext, if it exists. TheEndpointDetailsis used to determine the by key value.- Specified by:
processin interfaceHttpRequestInterceptor- Parameters:
request- the HTTP request to which the Forwarded header is to be added (notnull)entity- the entity details of the request (can benull)localContext- the HTTP context in which the request is being executed (notnull)- Throws:
HttpException- if there is an error processing the requestIOException- if an IO error occurs while processing the requestProtocolException- if the request authority is not specified
-