Skip to content

Commit 568466c

Browse files
committed
Add SetHostSocketFactory constructor directly from host string
1 parent 002a3ec commit 568466c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tls/src/main/java/org/bouncycastle/jsse/util/SetHostSocketFactory.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,18 @@ public static SocketFactory getDefault()
3333
return SSLSocketFactory.getDefault();
3434
}
3535

36-
protected final URL url;
36+
protected final String host;
3737

3838
public SetHostSocketFactory(SSLSocketFactory delegate, URL url)
39+
{
40+
this(delegate, url == null ? null : url.getHost());
41+
}
42+
43+
public SetHostSocketFactory(SSLSocketFactory delegate, String host)
3944
{
4045
super(delegate);
4146

42-
this.url = url;
47+
this.host = host;
4348
}
4449

4550
/**
@@ -63,17 +68,13 @@ public <V> V call(Callable<V> callable) throws Exception
6368
@Override
6469
protected Socket configureSocket(Socket s)
6570
{
66-
if (url != null && s instanceof BCSSLSocket)
71+
if (host != null && s instanceof BCSSLSocket)
6772
{
6873
BCSSLSocket ssl = (BCSSLSocket)s;
6974

70-
String host = url.getHost();
71-
if (host != null)
72-
{
73-
LOG.fine("Setting host on socket: " + host);
75+
LOG.fine("Setting host on socket: " + host);
7476

75-
ssl.setHost(host);
76-
}
77+
ssl.setHost(host);
7778
}
7879
return s;
7980
}

0 commit comments

Comments
 (0)