Skip to content

Commit

Permalink
allow for sni enabled endpoints re issue Netflix#337
Browse files Browse the repository at this point in the history
  • Loading branch information
clatko committed Nov 14, 2018
1 parent 304e38c commit 152b491
Showing 1 changed file with 24 additions and 0 deletions.
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,10 @@
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 rx.Observable;
import rx.functions.Func1;
Expand Down Expand Up @@ -511,6 +518,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 {
Server server = getRxClients().entrySet().iterator().next().getKey();
url = new URL(server.getScheme() + "://" + server.getHost());

SSLParameters sslParameters = new SSLParameters();
List<SNIServerName> sniServerNames = new ArrayList<>();
sniServerNames.add(new SNIHostName(url.getHost()));
sslParameters.setServerNames(sniServerNames);
myEngine.setSSLParameters(sslParameters);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}

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

0 comments on commit 152b491

Please sign in to comment.