Top Description Methods
org.springframework.http.client

public Interface ClientHttpRequestInterceptor

Known Direct Implementers
org.springframework.http.client.support.BasicAuthenticationInterceptor
Annotations
@FunctionalInterface
Imports
java.io.IOException, org.springframework.http.HttpRequest

Contract to intercept client-side HTTP requests. Implementations can be registered with org.springframework.web.client.RestClient or org.springframework.web.client.RestTemplate to modify the outgoing request and/or the incoming response.
Author
Arjen Poutsma
Since
3.1

Method Summary

Modifier and TypeMethod and Description
public ClientHttpResponse

Returns:

the response
intercept
(HttpRequest
the request, containing method, URI, and headers
request
,
byte[]
the body of the request
body
,
ClientHttpRequestExecution
the request execution
execution
)

Intercept the given request, and return a response.

Method Detail

interceptback to summary
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException

Intercept the given request, and return a response. The given ClientHttpRequestExecution allows the interceptor to pass on the request and response to the next entity in the chain.

A typical implementation of this method would follow the following pattern:

  1. Examine the request and body.
  2. Optionally wrap the request to filter HTTP attributes.
  3. Optionally modify the body of the request.
  4. Optionally wrap the response to filter HTTP attributes.

Note

if the interceptor throws an exception after receiving a response, it must close the response via ClientHttpResponse#close().

Parameters
request:HttpRequest

the request, containing method, URI, and headers

body:byte[]

the body of the request

execution:ClientHttpRequestExecution

the request execution

Returns:ClientHttpResponse

the response

Exceptions
IOException:
in case of I/O errors