Skip to content

Commit

Permalink
for alibaba#4236,fix error with the Apache HTTP client "Content-Lengt…
Browse files Browse the repository at this point in the history
…h Header Already Present" (alibaba#4237)
  • Loading branch information
Maijh97 authored Nov 16, 2020
1 parent bcd62d5 commit 0a983c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.alibaba.nacos.common.http.client.request.DefaultHttpClientRequest;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.RequestContent;

/**
* apache http client factory implements.
Expand All @@ -33,7 +34,9 @@ public final NacosRestTemplate createNacosRestTemplate() {
final HttpClientConfig originalRequestConfig = buildHttpClientConfig();
final RequestConfig requestConfig = getRequestConfig();
return new NacosRestTemplate(assignLogger(), new DefaultHttpClientRequest(
HttpClients.custom().setDefaultRequestConfig(requestConfig)
HttpClients.custom()
.addInterceptorLast(new RequestContent(true))
.setDefaultRequestConfig(requestConfig)
.setUserAgent(originalRequestConfig.getUserAgent())
.setMaxConnTotal(originalRequestConfig.getMaxConnTotal())
.setMaxConnPerRoute(originalRequestConfig.getMaxConnPerRoute())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alibaba.nacos.common.utils.BiConsumer;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.protocol.RequestContent;
import org.slf4j.Logger;

import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -70,7 +71,9 @@ public NacosAsyncRestTemplate createNacosAsyncRestTemplate() {
final HttpClientConfig originalRequestConfig = buildHttpClientConfig();
final RequestConfig requestConfig = getRequestConfig();
return new NacosAsyncRestTemplate(assignLogger(), new DefaultAsyncHttpClientRequest(
HttpAsyncClients.custom().setDefaultRequestConfig(requestConfig)
HttpAsyncClients.custom()
.addInterceptorLast(new RequestContent(true))
.setDefaultRequestConfig(requestConfig)
.setMaxConnTotal(originalRequestConfig.getMaxConnTotal())
.setMaxConnPerRoute(originalRequestConfig.getMaxConnPerRoute())
.setUserAgent(originalRequestConfig.getUserAgent()).build()));
Expand Down

0 comments on commit 0a983c8

Please sign in to comment.