Skip to content

Commit d9d8a79

Browse files
committed
Update Netty4ClientHttpRequestFactory buffer size
This change deprecates the maxRequestSize property and adds maxResponseSize instead. The latter is required to create Netty's HttpObjectAggregator and aggregates responses. The maxRequestSize property is already removed in the master branch and will not be available starting with 4.2. Issue: SPR-12623
1 parent 0484016 commit d9d8a79

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -65,7 +65,7 @@ public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method,
6565
this.bootstrap = bootstrap;
6666
this.uri = uri;
6767
this.method = method;
68-
this.body = new ByteBufOutputStream(Unpooled.buffer(maxRequestSize));
68+
this.body = new ByteBufOutputStream(Unpooled.buffer(1024, maxRequestSize));
6969
}
7070

7171

spring-web/src/main/java/org/springframework/http/client/Netty4ClientHttpRequestFactory.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@
4343
* across multiple clients.
4444
*
4545
* @author Arjen Poutsma
46+
* @author Rossen Stoyanchev
4647
* @since 4.1.2
4748
*/
4849
public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
@@ -51,16 +52,25 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
5152
/**
5253
* The default maximum request size.
5354
* @see #setMaxRequestSize(int)
55+
* @deprecated
5456
*/
5557
public static final int DEFAULT_MAX_REQUEST_SIZE = 1024 * 1024 * 10;
5658

59+
/**
60+
* The default maximum response size.
61+
* @see #setMaxResponseSize(int)
62+
*/
63+
public static final int DEFAULT_MAX_RESPONSE_SIZE = 1024 * 1024 * 10;
64+
5765

5866
private final EventLoopGroup eventLoopGroup;
5967

6068
private final boolean defaultEventLoopGroup;
6169

6270
private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE;
6371

72+
private int maxResponseSize = DEFAULT_MAX_REQUEST_SIZE;
73+
6474
private SslContext sslContext;
6575

6676
private volatile Bootstrap bootstrap;
@@ -94,11 +104,24 @@ public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) {
94104
* Set the default maximum request size.
95105
* <p>By default this is set to {@link #DEFAULT_MAX_REQUEST_SIZE}.
96106
* @see HttpObjectAggregator#HttpObjectAggregator(int)
107+
* @deprecated as of 4.1.5 this property is no longer supported;
108+
* effectively renamed to {@link #setMaxResponseSize(int)}.
97109
*/
98110
public void setMaxRequestSize(int maxRequestSize) {
99111
this.maxRequestSize = maxRequestSize;
100112
}
101113

114+
/**
115+
* Set the default maximum response size.
116+
* <p>By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}.
117+
* @see HttpObjectAggregator#HttpObjectAggregator(int)
118+
* @since 4.1.5
119+
*/
120+
public void setMaxResponseSize(int maxResponseSize) {
121+
this.maxResponseSize = maxResponseSize;
122+
}
123+
124+
102125
/**
103126
* Set the SSL context. When configured it is used to create and insert an
104127
* {@link io.netty.handler.ssl.SslHandler} in the channel pipeline.
@@ -120,7 +143,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
120143
pipeline.addLast(sslContext.newHandler(channel.alloc()));
121144
}
122145
pipeline.addLast(new HttpClientCodec());
123-
pipeline.addLast(new HttpObjectAggregator(maxRequestSize));
146+
pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
124147
}
125148
});
126149
this.bootstrap = bootstrap;

0 commit comments

Comments
 (0)