From a6079fcd1727cda9efa0c21212930717c58e7b9d Mon Sep 17 00:00:00 2001 From: Fishtail <49390359+fuyuwei01@users.noreply.github.com> Date: Mon, 15 Jul 2024 19:50:08 +0800 Subject: [PATCH] fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5 (#1337) --- CHANGELOG.md | 1 + .../resttemplate/RouterLabelRestTemplateInterceptor.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de45c9eaa..ff5774879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,3 +4,4 @@ - [feat:upgrade jackson version.](https://github.com/Tencent/spring-cloud-tencent/pull/1259) - [fix:fix ApplicationContextAwareUtils NPE bug.](https://github.com/Tencent/spring-cloud-tencent/pull/1294) - [feat:upgrade jacoco version.](https://github.com/Tencent/spring-cloud-tencent/pull/1308) +- [fix: fix RouterLabelRestTemplateInterceptor add response headers exception with httpclient5.](https://github.com/Tencent/spring-cloud-tencent/pull/1337) 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 808b2f687..b23c5e14e 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 @@ -45,6 +45,7 @@ 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; @@ -104,7 +105,8 @@ public ClientHttpResponse intercept(@NonNull HttpRequest request, @NonNull byte[ 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))); }