Skip to content

Commit 3a4561c

Browse files
author
gjeanmart
committed
Detect ssl from a multiaddress - Dependent of a java-multiaddress change
[ multiformats/java-multiaddr#8 ]
1 parent b02a58a commit 3a4561c

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

src/main/java/io/ipfs/api/IPFS.java

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,17 @@ public enum PinType {all, direct, indirect, recursive}
4141
public final Name name = new Name();
4242
public final Pubsub pubsub = new Pubsub();
4343

44-
4544
public IPFS(String host, int port) {
46-
this(host, port, "/api/v0/");
45+
this(host, port, "/api/v0/", false);
4746
}
4847

49-
public IPFS(String host, int port, boolean ssl) {
50-
this(host, port, "/api/v0/", ssl);
51-
}
52-
5348
public IPFS(String multiaddr) {
5449
this(new MultiAddress(multiaddr));
5550
}
5651

5752
public IPFS(MultiAddress addr) {
58-
this(addr.getHost(), addr.getTCPPort(), "/api/v0/");
59-
}
60-
61-
public IPFS(MultiAddress addr, boolean ssl) {
62-
this(addr.getHost(), addr.getTCPPort(), "/api/v0/", ssl);
63-
}
64-
65-
public IPFS(String host, int port, String version) {
66-
this(host, port, version, false);
67-
}
53+
this(addr.getHost(), addr.getTCPPort(), "/api/v0/", detectSSL(addr));
54+
}
6855

6956
public IPFS(String host, int port, String version, boolean ssl) {
7057
this.host = host;
@@ -737,4 +724,8 @@ private static final byte[] readFully(InputStream in) throws IOException {
737724
resp.write(buf, 0, r);
738725
return resp.toByteArray();
739726
}
727+
728+
private static boolean detectSSL(MultiAddress multiaddress) {
729+
return multiaddress.toString().contains("https");
730+
}
740731
}

0 commit comments

Comments
 (0)