Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for sni enabled endpoints re issue #337 #391

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@
import io.reactivex.netty.protocol.http.client.HttpClientResponse;
import io.reactivex.netty.servo.http.HttpClientListener;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand All @@ -48,7 +52,13 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLParameters;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import rx.Observable;
import rx.functions.Func1;
Expand Down Expand Up @@ -84,7 +94,7 @@ public class LoadBalancingHttpClient<I, O> extends LoadBalancingRxClientWithPool
implements HttpClient<I, O> {

private static final HttpClientConfig DEFAULT_RX_CONFIG = HttpClientConfig.Builder.newDefaultConfig();

private static final Logger logger = LoggerFactory.getLogger(LoadBalancingHttpClient.class);
private final String requestIdHeaderName;
private final HttpRequestIdProvider requestIdProvider;
private final List<ExecutionListener<HttpClientRequest<I>, HttpClientResponse<O>>> listeners;
Expand Down Expand Up @@ -511,6 +521,23 @@ protected HttpClient<I, O> createRxClient(Server server) {
@Override
public SSLEngine createSSLEngine(ByteBufAllocator allocator) {
SSLEngine myEngine = super.createSSLEngine(allocator);

URL url = null;
if(null!=getRxClients()) {
try {
SSLParameters sslParameters = new SSLParameters();
List<SNIServerName> sniServerNames = new ArrayList<>();
for(Server server: getRxClients().keySet()) {
url = new URL(server.getScheme() + "://" + server.getHost());
sniServerNames.add(new SNIHostName(url.getHost()));
}
sslParameters.setServerNames(sniServerNames);
myEngine.setSSLParameters(sslParameters);
} catch (MalformedURLException e) {
logger.error("MalformedURL: " + url.toString());
}
}

myEngine.setUseClientMode(true);
return myEngine;
}
Expand Down