4848 * <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for
4949 * sharing across multiple clients.
5050 *
51+ * <p>Note that this implementation consistently closes the HTTP connection on each
52+ * request.
53+ *
5154 * @author Arjen Poutsma
5255 * @author Rossen Stoyanchev
5356 * @author Brian Clozel
@@ -78,8 +81,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
7881
7982 private volatile Bootstrap bootstrap ;
8083
81- private volatile Bootstrap sslBootstrap ;
82-
8384
8485 /**
8586 * Create a new {@code Netty4ClientHttpRequestFactory} with a default
@@ -177,20 +178,17 @@ private Netty4ClientHttpRequest createRequestInternal(URI uri, HttpMethod httpMe
177178 private Bootstrap getBootstrap (URI uri ) {
178179 boolean isSecure = (uri .getPort () == 443 || "https" .equalsIgnoreCase (uri .getScheme ()));
179180 if (isSecure ) {
180- if (this .sslBootstrap == null ) {
181- this .sslBootstrap = buildBootstrap (true );
182- }
183- return this .sslBootstrap ;
181+ return buildBootstrap (uri , true );
184182 }
185183 else {
186184 if (this .bootstrap == null ) {
187- this .bootstrap = buildBootstrap (false );
185+ this .bootstrap = buildBootstrap (uri , false );
188186 }
189187 return this .bootstrap ;
190188 }
191189 }
192190
193- private Bootstrap buildBootstrap (boolean isSecure ) {
191+ private Bootstrap buildBootstrap (URI uri , boolean isSecure ) {
194192 Bootstrap bootstrap = new Bootstrap ();
195193 bootstrap .group (this .eventLoopGroup ).channel (NioSocketChannel .class )
196194 .handler (new ChannelInitializer <SocketChannel >() {
@@ -200,7 +198,7 @@ protected void initChannel(SocketChannel channel) throws Exception {
200198 ChannelPipeline pipeline = channel .pipeline ();
201199 if (isSecure ) {
202200 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 () ));
204202 }
205203 pipeline .addLast (new HttpClientCodec ());
206204 pipeline .addLast (new HttpObjectAggregator (maxResponseSize ));
0 commit comments