From 0542fe5232a54bc7f92c5ee43856ebe4acd5d835 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 11 Oct 2023 12:46:36 +0100 Subject: [PATCH] Update ClientHttpRequestInterceptor javadoc Clarify the interceptor is responsible for closing the response if it throws an exception after receiving it. Closes gh-29751 --- .../client/ClientHttpRequestInterceptor.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestInterceptor.java b/spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestInterceptor.java index 82e6f7be71..c4d36bcf72 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestInterceptor.java +++ b/spring-web/src/main/java/org/springframework/http/client/ClientHttpRequestInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,10 @@ import java.io.IOException; import org.springframework.http.HttpRequest; /** - * Intercepts client-side HTTP requests. Implementations of this interface can be - * {@linkplain org.springframework.web.client.RestTemplate#setInterceptors registered} - * with the {@link org.springframework.web.client.RestTemplate RestTemplate}, - * as to modify the outgoing {@link ClientHttpRequest} and/or the incoming - * {@link ClientHttpResponse}. - * - *

The main entry point for interceptors is - * {@link #intercept(HttpRequest, byte[], ClientHttpRequestExecution)}. + * Contract to intercept client-side HTTP requests. Implementations can be + * registered with {@link org.springframework.web.client.RestClient} or + * {@link org.springframework.web.client.RestTemplate} to modify the outgoing + * request and/or the incoming response. * * @author Arjen Poutsma * @since 3.1 @@ -55,6 +51,8 @@ public interface ClientHttpRequestInterceptor { * *

  • 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 {@link ClientHttpResponse#close()}. * @param request the request, containing method, URI, and headers * @param body the body of the request * @param execution the request execution