Package org.springframework.http.client
Interface ClientHttpRequestInterceptor
- All Known Implementing Classes:
- BasicAuthenticationInterceptor
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Contract to intercept client-side HTTP requests. Implementations can be
 registered with 
RestClient or
 RestTemplate to modify the outgoing
 request and/or the incoming response.- Since:
- 3.1
- Author:
- Arjen Poutsma
- 
Method SummaryModifier and TypeMethodDescriptiondefault ClientHttpRequestInterceptorandThen(ClientHttpRequestInterceptor interceptor) Return a new interceptor that invokesthisinterceptor first, and then the one that's passed in.default ClientHttpRequestExecutionapply(ClientHttpRequestExecution execution) Return a new execution that invokesthisinterceptor, and then delegates to the given execution.intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) Intercept the given request, and return a response.
- 
Method Details- 
interceptClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException Intercept the given request, and return a response. The givenClientHttpRequestExecutionallows 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: - Examine the request and body.
- Optionally wrap the request to filter HTTP attributes.
- Optionally modify the body of the request.
- either execute the request using
 ClientHttpRequestExecution.execute(HttpRequest, byte[])
- or do not execute the request to block the execution altogether
- 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- the request, containing method, URI, and headers
- body- the body of the request
- execution- the request execution
- Returns:
- the response
- Throws:
- IOException- in case of I/O errors
 
- 
andThenReturn a new interceptor that invokesthisinterceptor first, and then the one that's passed in.- Parameters:
- interceptor- the next interceptor
- Returns:
- a new interceptor that chains the two
- Since:
- 7.0
 
- 
applyReturn a new execution that invokesthisinterceptor, and then delegates to the given execution.- Parameters:
- execution- the execution to delegate to
- Returns:
- a new execution instance
- Since:
- 7.0
 
 
-