Skip to content

Commit 5bee112

Browse files
authored
[type: feat] body maxInMemorySize (#3640)
* "feat body maxInMemorySize" * fix ci error * fix ci error
1 parent 005a041 commit 5bee112

File tree

3 files changed

+37
-2
lines changed
  • shenyu-bootstrap/src/main/resources
  • shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/config
  • shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-httpclient/src/main/java/org/apache/shenyu/springboot/starter/plugin/httpclient

3 files changed

+37
-2
lines changed

shenyu-bootstrap/src/main/resources/application.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ shenyu:
121121
# writeTimeout: 3000
122122
# wiretap: false
123123
# keepAlive: false
124+
# maxInMemorySize: 16 * 1024 * 1024
124125
# pool:
125126
# type: ELASTIC
126127
# name: proxy

shenyu-plugin/shenyu-plugin-httpclient/src/main/java/org/apache/shenyu/plugin/httpclient/config/HttpClientProperties.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ public class HttpClientProperties {
116116
*/
117117
private boolean keepAlive;
118118

119+
/**
120+
* body max memory size, unit byte.
121+
*/
122+
private int maxInMemorySize;
123+
119124
/**
120125
* Gets strategy.
121126
*
@@ -369,6 +374,22 @@ public void setKeepAlive(final boolean keepAlive) {
369374
this.keepAlive = keepAlive;
370375
}
371376

377+
/**
378+
* get maxInMemorySize.
379+
* @return maxInMemorySize
380+
*/
381+
public int getMaxInMemorySize() {
382+
return maxInMemorySize;
383+
}
384+
385+
/**
386+
* set maxInMemorySize.
387+
* @param maxInMemorySize maxInMemorySize
388+
*/
389+
public void setMaxInMemorySize(final int maxInMemorySize) {
390+
this.maxInMemorySize = maxInMemorySize;
391+
}
392+
372393
/**
373394
* The type Pool.
374395
*/

shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-httpclient/src/main/java/org/apache/shenyu/springboot/starter/plugin/httpclient/HttpClientPluginConfiguration.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.context.annotation.Bean;
3636
import org.springframework.context.annotation.Configuration;
3737
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
38+
import org.springframework.web.reactive.function.client.ExchangeStrategies;
3839
import org.springframework.web.reactive.function.client.WebClient;
3940
import reactor.netty.http.client.HttpClient;
4041
import reactor.netty.resources.ConnectionProvider;
@@ -233,8 +234,20 @@ static class WebClientConfiguration {
233234
* @return the shenyu plugin
234235
*/
235236
@Bean
236-
public ShenyuPlugin webClientPlugin(final ObjectProvider<HttpClient> httpClient) {
237-
WebClient webClient = WebClient.builder()
237+
public ShenyuPlugin webClientPlugin(
238+
final HttpClientProperties properties,
239+
final ObjectProvider<HttpClient> httpClient) {
240+
WebClient.Builder builder = WebClient.builder();
241+
if (properties.getMaxInMemorySize() != 0) {
242+
// fix Exceeded limit on max bytes to buffer
243+
// detail see https://stackoverflow.com/questions/59326351/configure-spring-codec-max-in-memory-size-when-using-reactiveelasticsearchclient
244+
ExchangeStrategies strategies = ExchangeStrategies.builder()
245+
.codecs(codecs -> codecs.defaultCodecs().maxInMemorySize(properties.getMaxInMemorySize()))
246+
.build();
247+
builder = builder.exchangeStrategies(strategies);
248+
}
249+
250+
WebClient webClient = builder
238251
.clientConnector(new ReactorClientHttpConnector(Objects.requireNonNull(httpClient.getIfAvailable())))
239252
.build();
240253
return new WebClientPlugin(webClient);

0 commit comments

Comments
 (0)