From 54d04d80d5ef4382792e83d860302c55e350b946 Mon Sep 17 00:00:00 2001 From: Fishtail <49390359+fuyuwei01@users.noreply.github.com> Date: Tue, 13 Aug 2024 15:36:17 +0800 Subject: [PATCH] fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5 (#1376) Co-authored-by: Haotian Zhang Co-authored-by: gzoldou --- CHANGELOG.md | 1 + .../resttemplate/RouterLabelRestTemplateInterceptor.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c3e675a0..8ec260317 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ - [feat:upgrade jackson version.](https://github.com/Tencent/spring-cloud-tencent/pull/1258) - [fix:fix ApplicationContextAwareUtils NPE bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1296) - [feat:upgrade jacoco version.](https://github.com/Tencent/spring-cloud-tencent/pull/1307) +- [fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5.](https://github.com/Tencent/spring-cloud-tencent/pull/1376) diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/resttemplate/RouterLabelRestTemplateInterceptor.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/resttemplate/RouterLabelRestTemplateInterceptor.java index 3110a8e7e..e862a33e8 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/resttemplate/RouterLabelRestTemplateInterceptor.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/resttemplate/RouterLabelRestTemplateInterceptor.java @@ -44,6 +44,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.Ordered; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; @@ -103,7 +104,8 @@ public class RouterLabelRestTemplateInterceptor implements ClientHttpRequestInte ClientHttpResponse response = clientHttpRequestExecution.execute(request, body); if (!CollectionUtils.isEmpty(request.getHeaders().get(RouterConstant.ROUTER_LABEL_HEADER))) { - response.getHeaders().addAll(RouterConstant.ROUTER_LABEL_HEADER, Objects.requireNonNull(request.getHeaders() + HttpHeaders responseHeaders = HttpHeaders.writableHttpHeaders(response.getHeaders()); + responseHeaders.addAll(RouterConstant.ROUTER_LABEL_HEADER, Objects.requireNonNull(request.getHeaders() .get(RouterConstant.ROUTER_LABEL_HEADER))); }