Add SNI support in Netty4ClientHttpRequestFactory
This commit changes the `Bootstrap` to create a SSL Handler with
advisory peer information; this enables support for SNI.
Issue: SPR-15101
(cherry picked from commit 0c99346)
			
			
This commit is contained in:
		
							parent
							
								
									caebe72083
								
							
						
					
					
						commit
						28c7f65a25
					
				| 
						 | 
				
			
			@ -48,6 +48,9 @@ import org.springframework.util.Assert;
 | 
			
		|||
 * <p>Allows to use a pre-configured {@link EventLoopGroup} instance: useful for
 | 
			
		||||
 * sharing across multiple clients.
 | 
			
		||||
 *
 | 
			
		||||
 * <p>Note that this implementation consistently closes the HTTP connection on each
 | 
			
		||||
 * request.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Arjen Poutsma
 | 
			
		||||
 * @author Rossen Stoyanchev
 | 
			
		||||
 * @author Brian Clozel
 | 
			
		||||
| 
						 | 
				
			
			@ -78,8 +81,6 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
 | 
			
		|||
 | 
			
		||||
	private volatile Bootstrap bootstrap;
 | 
			
		||||
 | 
			
		||||
	private volatile Bootstrap sslBootstrap;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Create a new {@code Netty4ClientHttpRequestFactory} with a default
 | 
			
		||||
| 
						 | 
				
			
			@ -177,20 +178,17 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
 | 
			
		|||
	private Bootstrap getBootstrap(URI uri) {
 | 
			
		||||
		boolean isSecure = (uri.getPort() == 443 || "https".equalsIgnoreCase(uri.getScheme()));
 | 
			
		||||
		if (isSecure) {
 | 
			
		||||
			if (this.sslBootstrap == null) {
 | 
			
		||||
				this.sslBootstrap = buildBootstrap(true);
 | 
			
		||||
			}
 | 
			
		||||
			return this.sslBootstrap;
 | 
			
		||||
			return buildBootstrap(uri, true);
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			if (this.bootstrap == null) {
 | 
			
		||||
				this.bootstrap = buildBootstrap(false);
 | 
			
		||||
				this.bootstrap = buildBootstrap(uri, false);
 | 
			
		||||
			}
 | 
			
		||||
			return this.bootstrap;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private Bootstrap buildBootstrap(final boolean isSecure) {
 | 
			
		||||
	private Bootstrap buildBootstrap(final URI uri, final boolean isSecure) {
 | 
			
		||||
		Bootstrap bootstrap = new Bootstrap();
 | 
			
		||||
		bootstrap.group(this.eventLoopGroup).channel(NioSocketChannel.class)
 | 
			
		||||
				.handler(new ChannelInitializer<SocketChannel>() {
 | 
			
		||||
| 
						 | 
				
			
			@ -200,7 +198,7 @@ public class Netty4ClientHttpRequestFactory implements ClientHttpRequestFactory,
 | 
			
		|||
						ChannelPipeline pipeline = channel.pipeline();
 | 
			
		||||
						if (isSecure) {
 | 
			
		||||
							Assert.notNull(sslContext, "sslContext should not be null");
 | 
			
		||||
							pipeline.addLast(sslContext.newHandler(channel.alloc()));
 | 
			
		||||
							pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort()));
 | 
			
		||||
						}
 | 
			
		||||
						pipeline.addLast(new HttpClientCodec());
 | 
			
		||||
						pipeline.addLast(new HttpObjectAggregator(maxResponseSize));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue