48
48
* <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for
49
49
* sharing across multiple clients.
50
50
*
51
+ * <p>Note that this implementation consistently closes the HTTP connection on each
52
+ * request.
53
+ *
51
54
* @author Arjen Poutsma
52
55
* @author Rossen Stoyanchev
53
56
* @author Brian Clozel
@@ -78,8 +81,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
78
81
79
82
private volatile Bootstrap bootstrap ;
80
83
81
- private volatile Bootstrap sslBootstrap ;
82
-
83
84
84
85
/**
85
86
* Create a new {@code Netty4ClientHttpRequestFactory} with a default
@@ -177,20 +178,17 @@ private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMe
177
178
private Bootstrap getBootstrap (URI uri ) {
178
179
boolean isSecure = (uri .getPort () == 443 || "https" .equalsIgnoreCase (uri .getScheme ()));
179
180
if (isSecure ) {
180
- if (this .sslBootstrap == null ) {
181
- this .sslBootstrap = buildBootstrap (true );
182
- }
183
- return this .sslBootstrap ;
181
+ return buildBootstrap (uri , true );
184
182
}
185
183
else {
186
184
if (this .bootstrap == null ) {
187
- this .bootstrap = buildBootstrap (false );
185
+ this .bootstrap = buildBootstrap (uri , false );
188
186
}
189
187
return this .bootstrap ;
190
188
}
191
189
}
192
190
193
- private Bootstrap buildBootstrap (boolean isSecure ) {
191
+ private Bootstrap buildBootstrap (URI uri , boolean isSecure ) {
194
192
Bootstrap bootstrap = new Bootstrap ();
195
193
bootstrap .group (this .eventLoopGroup ).channel (NioSocketChannel .class )
196
194
.handler (new ChannelInitializer <SocketChannel >() {
@@ -200,7 +198,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
200
198
ChannelPipeline pipeline = channel .pipeline ();
201
199
if (isSecure ) {
202
200
Assert .notNull (sslContext , "sslContext should not be null" );
203
- pipeline .addLast (sslContext .newHandler (channel .alloc ()));
201
+ pipeline .addLast (sslContext .newHandler (channel .alloc (), uri . getHost (), uri . getPort () ));
204
202
}
205
203
pipeline .addLast (new HttpClientCodec ());
206
204
pipeline .addLast (new HttpObjectAggregator (maxResponseSize ));
0 commit comments