Skip to content

Commit 525edf8

Browse files
committed
Add support for proxy https
1 parent 10bc0f9 commit 525edf8

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/main/java/io/simplelocalize/cli/client/SystemProxySelector.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static ProxyConfiguration getHttpProxyValueOrNull(String httpProxyValue)
1515
return null;
1616
}
1717

18-
boolean isHttpOrHttps = httpProxyValue.startsWith("http://") || httpProxyValue.startsWith("https://");
18+
final boolean isHttp = httpProxyValue.startsWith("http://");
19+
final boolean isHttps = httpProxyValue.startsWith("https://");
20+
final boolean isHttpOrHttps = isHttp || isHttps;
1921
if (isHttpOrHttps)
2022
{
2123
httpProxyValue = httpProxyValue
@@ -28,7 +30,7 @@ public static ProxyConfiguration getHttpProxyValueOrNull(String httpProxyValue)
2830

2931
String addressUrl;
3032
String authenticationString = "";
31-
boolean hasAuthentication = httpProxyValue.contains("@");
33+
final boolean hasAuthentication = httpProxyValue.contains("@");
3234
if (hasAuthentication)
3335
{
3436
String[] authenticationAndAddress = httpProxyValue.split("@");
@@ -40,8 +42,8 @@ public static ProxyConfiguration getHttpProxyValueOrNull(String httpProxyValue)
4042
}
4143

4244
String host;
43-
int port = 80;
44-
boolean hasHostnameAndPort = addressUrl.contains(":");
45+
int port = isHttp ? 80 : 443;
46+
final boolean hasHostnameAndPort = addressUrl.contains(":");
4547
if (hasHostnameAndPort)
4648
{
4749
String[] hostAndPortParts = addressUrl.split(":");
@@ -54,7 +56,7 @@ public static ProxyConfiguration getHttpProxyValueOrNull(String httpProxyValue)
5456

5557
String username = null;
5658
String password = null;
57-
boolean hasUsernameAndPassword = authenticationString.contains(":");
59+
final boolean hasUsernameAndPassword = authenticationString.contains(":");
5860
if (hasUsernameAndPassword)
5961
{
6062
String[] usernameAndPassword = authenticationString.split(":");

src/test/java/io/simplelocalize/cli/client/SystemProxySelectorTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ private static Stream<Arguments> provideArguments()
1919
{
2020
return Stream.of(
2121
of("http://123.456.789.000", new ProxyConfiguration().setHost("123.456.789.000").setPort(80).setUsername(null).setPassword(null)),
22+
of("https://123.456.789.000", new ProxyConfiguration().setHost("123.456.789.000").setPort(443).setUsername(null).setPassword(null)),
2223
of("http://123.456.789.000:8080", new ProxyConfiguration().setHost("123.456.789.000").setPort(8080).setUsername(null).setPassword(null)),
24+
of("https://123.456.789.000:8080", new ProxyConfiguration().setHost("123.456.789.000").setPort(8080).setUsername(null).setPassword(null)),
2325
of("http://foo:[email protected]", new ProxyConfiguration().setHost("123.456.789.000").setPort(80).setUsername("foo").setPassword("bar")),
24-
of("http://foo:[email protected]:8080", new ProxyConfiguration().setHost("123.456.789.000").setPort(8080).setUsername("foo").setPassword("bar"))
26+
of("https://foo:[email protected]", new ProxyConfiguration().setHost("123.456.789.000").setPort(443).setUsername("foo").setPassword("bar")),
27+
of("http://foo:[email protected]:8080", new ProxyConfiguration().setHost("123.456.789.000").setPort(8080).setUsername("foo").setPassword("bar")),
28+
of("https://foo:[email protected]:8080", new ProxyConfiguration().setHost("123.456.789.000").setPort(8080).setUsername("foo").setPassword("bar"))
2529
);
2630
}
2731

0 commit comments

Comments
 (0)