Package kong.unirest.core
Interface Interceptor
-
public interface Interceptor
Each configuration of Unirest has an interceptor. This has three stages: * onRequest allows you to modify of view the request before it it sent * onResponse allows you to view the response. This includes both successful and failed but valid responses * onFail is called if a total connection or network failure occurred.
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default HttpResponse<?>
onFail(Exception e, HttpRequestSummary request, Config config)
Called in the case of a total failure.default void
onRequest(HttpRequest<?> request, Config config)
Called just before a request.default void
onResponse(HttpResponse<?> response, HttpRequestSummary request, Config config)
Called just after the request.
-
-
-
Method Detail
-
onRequest
default void onRequest(HttpRequest<?> request, Config config)
Called just before a request. This can be used to view or modify the request. this could be used for things like - Logging the request - Injecting tracer headers - Record metrics The default implementation does nothing at all- Parameters:
request
- the requestconfig
- the current configuration
-
onResponse
default void onResponse(HttpResponse<?> response, HttpRequestSummary request, Config config)
Called just after the request. This can be used to view the response, Perhaps for logging purposes or just because you're curious.- Parameters:
response
- the responserequest
- a summary of the requestconfig
- the current configuration
-
onFail
default HttpResponse<?> onFail(Exception e, HttpRequestSummary request, Config config) throws UnirestException
Called in the case of a total failure. This would be where Unirest was completely unable to make a request at all for reasons like: - DNS errors - Connection failure - Connection or Socket timeout - SSL/TLS errors The default implimentation simply wraps the exception in a UnirestException and throws it. It is possible to return a different response object from the original if you really didn't want to every throw exceptions. Keep in mind that this is a lie Nevertheless, you could return something like a kong.unirest.core.FailedResponse- Parameters:
e
- the exceptionrequest
- the original requestconfig
- the current config- Returns:
- a alternative response.
- Throws:
UnirestException
-
-