Skip to content

Commit fd426aa

Browse files
committed
Update Netty4ClientHttpRequestFactory buffer size
Before this change, the maxRequestSize property was used (incorrectly) to limit both the size of the request and response. The change: - removes maxRequestSize and therefore no longer places limits on the size of the request thus matching to AbstractBufferingClientHttpRequest which is the base class for other buffering client implementations. - adds maxResponseSize property required to create Netty's HttpObjectAggregator for aggregating responses. Issue: SPR-12623
1 parent f017cc3 commit fd426aa

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

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

Lines changed: 5 additions & 3 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.
@@ -41,13 +41,15 @@
4141
import org.springframework.util.concurrent.ListenableFuture;
4242
import org.springframework.util.concurrent.SettableListenableFuture;
4343

44+
4445
/**
4546
* {@link org.springframework.http.client.ClientHttpRequest} implementation that uses
4647
* Netty 4 to execute requests.
4748
*
4849
* <p>Created via the {@link Netty4ClientHttpRequestFactory}.
4950
*
5051
* @author Arjen Poutsma
52+
* @author Rossen Stoyanchev
5153
* @since 4.1.2
5254
*/
5355
class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements ClientHttpRequest {
@@ -61,11 +63,11 @@ class Netty4ClientHttpRequest extends AbstractAsyncClientHttpRequest implements
6163
private final ByteBufOutputStream body;
6264

6365

64-
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) {
66+
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method) {
6567
this.bootstrap = bootstrap;
6668
this.uri = uri;
6769
this.method = method;
68-
this.body = new ByteBufOutputStream(Unpooled.buffer(maxRequestSize));
70+
this.body = new ByteBufOutputStream(Unpooled.buffer(1024));
6971
}
7072

7173

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

Lines changed: 14 additions & 11 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.
@@ -35,6 +35,7 @@
3535
import org.springframework.http.HttpMethod;
3636
import org.springframework.util.Assert;
3737

38+
3839
/**
3940
* {@link org.springframework.http.client.ClientHttpRequestFactory} implementation that
4041
* uses <a href="http://netty.io/">Netty 4</a> to create requests.
@@ -43,23 +44,24 @@
4344
* across multiple clients.
4445
*
4546
* @author Arjen Poutsma
47+
* @author Rossen Stoyanchev
4648
* @since 4.1.2
4749
*/
4850
public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
4951
AsyncClientHttpRequestFactory, InitializingBean, DisposableBean {
5052

5153
/**
52-
* The default maximum request size.
53-
* @see #setMaxRequestSize(int)
54+
* The default maximum response size.
55+
* @see #setMaxResponseSize(int)
5456
*/
55-
public static final int DEFAULT_MAX_REQUEST_SIZE = 1024 * 1024 * 10;
57+
public static final int DEFAULT_MAX_RESPONSE_SIZE = 1024 * 1024 * 10;
5658

5759

5860
private final EventLoopGroup eventLoopGroup;
5961

6062
private final boolean defaultEventLoopGroup;
6163

62-
private int maxRequestSize = DEFAULT_MAX_REQUEST_SIZE;
64+
private int maxResponseSize = DEFAULT_MAX_RESPONSE_SIZE;
6365

6466
private SslContext sslContext;
6567

@@ -91,12 +93,13 @@ public Netty4ClientHttpRequestFactory(EventLoopGroup eventLoopGroup) {
9193

9294

9395
/**
94-
* Set the default maximum request size.
95-
* <p>By default this is set to {@link #DEFAULT_MAX_REQUEST_SIZE}.
96+
* Set the default maximum response size.
97+
* <p>By default this is set to {@link #DEFAULT_MAX_RESPONSE_SIZE}.
9698
* @see HttpObjectAggregator#HttpObjectAggregator(int)
99+
* @since 4.1.5
97100
*/
98-
public void setMaxRequestSize(int maxRequestSize) {
99-
this.maxRequestSize = maxRequestSize;
101+
public void setMaxResponseSize(int maxResponseSize) {
102+
this.maxResponseSize = maxResponseSize;
100103
}
101104

102105
/**
@@ -120,7 +123,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
120123
pipeline.addLast(sslContext.newHandler(channel.alloc()));
121124
}
122125
pipeline.addLast(new HttpClientCodec());
123-
pipeline.addLast(new HttpObjectAggregator(maxRequestSize));
126+
pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
124127
}
125128
});
126129
this.bootstrap = bootstrap;
@@ -145,7 +148,7 @@ public AsyncClientHttpRequest createAsyncRequest(URI uri, HttpMethod httpMethod)
145148
}
146149

147150
private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMethod) {
148-
return new Netty4ClientHttpRequest(getBootstrap(), uri, httpMethod, this.maxRequestSize);
151+
return new Netty4ClientHttpRequest(getBootstrap(), uri, httpMethod);
149152
}
150153

151154

0 commit comments

Comments
 (0)