Class ViaRequest
- java.lang.Object
-
- org.apache.hc.core5.http.protocol.ViaRequest
-
- All Implemented Interfaces:
HttpRequestInterceptor
@Contract(threading=IMMUTABLE) public class ViaRequest extends java.lang.Object implements HttpRequestInterceptor
This request interceptor can be used by an HTTP proxy or intemediary to add theHttpHeaders.VIAHTTP header to outgoing request messages.The
HttpHeaders.VIAheader is used to indicate intermediate protocols and recipients between the user agent and the server (on requests) or between the origin server and the client (on responses). It can be used for tracking message forwards, avoiding request loops, and identifying the protocol capabilities of senders along the request/response chain. Each member of theHttpHeaders.VIAheader field value represents a proxy or gateway that has forwarded the message.A proxy MUST send an appropriate
HttpHeaders.VIAheader field, as described in the HTTP specification, in each message that it forwards. An HTTP-to-HTTP gateway MUST send an appropriateHttpHeaders.VIAheader field in each inbound request message and MAY send aHttpHeaders.VIAheader field in forwarded response messages.This interceptor ensures that the
HttpHeaders.VIAheader is added to the request only if it has not been added previously, as per the HTTP specification. Additionally, it updates the values in theHttpHeaders.VIAheader correctly in case of multiple intermediate protocols or recipients, by appending its own information about how the message was received to the end of the header field value.- Since:
- 5.3
-
-
Field Summary
Fields Modifier and Type Field Description static HttpRequestInterceptorINSTANCESingleton instance.
-
Constructor Summary
Constructors Constructor Description ViaRequest()Constructs a newViaRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidprocess(HttpRequest request, EntityDetails entity, HttpContext context)Adds the HTTPHttpHeaders.VIAheader to the request if it does not already exist.
-
-
-
Field Detail
-
INSTANCE
public static final HttpRequestInterceptor INSTANCE
Singleton instance.
-
-
Method Detail
-
process
public void process(HttpRequest request, EntityDetails entity, HttpContext context) throws ProtocolException, java.io.IOException
Adds the HTTPHttpHeaders.VIAheader to the request if it does not already exist.This method ensures that the version of the request is HTTP/1.1 or higher, and adds the Via header in the format
<protocol> <version> <host>, where<protocol>is the protocol name,<version>is the major and minor version of the request, and<host>is the value of the Host header.In case the
HttpHeaders.VIAheader already exists, this method updates its value by appending the new protocol information in the same format.If the version of the request is lower than
HTTP/1.1or the request authority not being specified, this method throws aProtocolException.- Specified by:
processin interfaceHttpRequestInterceptor- Parameters:
request- the request object to modifyentity- the entity for the request, may benullcontext- the context for the request- Throws:
ProtocolException- if there was a protocol error, such as the request version being lower thanHTTP/1.1, or the request authority not being specifiedjava.io.IOException- if there was an I/O error
-
-