Skip to content

Commit

Permalink
Issue #88. Rework and document proxy configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray authored and gunnarmorling committed Feb 8, 2021
1 parent fe17543 commit ddac9d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
27 changes: 27 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,33 @@ layrry-launcher-{layrry-version}-all.jar \
--properties https://server:port/path/to/versions.properties
----

=== Proxy Configuration

You may need to configure a proxy when using the remote configuration feature. The following properties may be used to
configure a proxy

[options="header"]
|===
| Key | Description
| use.proxy | Whether to use any proxy or not. Defaults to `false`.
| http.proxy | Whether to use HTTP proxy or not. Defaults to `false`.
| http.proxyHost | Defaults to empty String.
| http.proxyport | Defaults to `80`.
| http.proxyUser | Defaults to empty String.
| http.proxyPassword | Defaults to empty String.
| http.nonProxyHosts | Defaults to `localhost\|127.*\|[::1]`.
| https.proxy | Whether to use HTTPS proxy or not. Defaults to `false`.
| https.proxyHost | Defaults to empty String.
| https.proxyport | Defaults to `443`.
| https.proxyUser | Defaults to empty String.
| https.proxyPassword | Defaults to empty String.
| socks.proxy | Whether to use SOCKS proxy or not. Defaults to `false`.
| socksProxyHost | Defaults to empty String.
| socksProxyPort | Defaults to `1080`.
| socks.proxyUser | Defaults to empty String.
| socks.proxyPassword | Defaults to empty String.
|===

== Using the Layrry API

In addition to the YAML-based/TOML-based launcher, Layrry provides also a Java API for assembling and running layered applications.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class UrlDownloader {
static Path download(URL url, Properties properties) {
HttpClient.Builder builder = HttpClient.newBuilder()
.connectTimeout(Duration.of(getLong("connection.timeout", properties, 30_000), ChronoUnit.MILLIS))
.followRedirects(HttpClient.Redirect.ALWAYS);
.followRedirects(HttpClient.Redirect.ALWAYS)
.version(HttpClient.Version.HTTP_2);

builder = setupProxy(builder, url, properties);
builder = setupAuthentication(builder, url, properties);
Expand All @@ -64,6 +65,7 @@ private static HttpRequest createRequest(URL url) {
try {
return HttpRequest.newBuilder()
.uri(url.toURI())
.version(HttpClient.Version.HTTP_2)
.build();
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid URL", e);
Expand Down Expand Up @@ -96,24 +98,28 @@ private static HttpResponse.BodyHandler<Path> fileBodyHandler(URL url) {
}

private static HttpClient.Builder setupProxy(HttpClient.Builder builder, URL url, Properties properties) {
if (getBoolean("http.proxy", properties)) {
setIfUndefined("http.proxyHost", properties, "");
setIfUndefined("http.proxyPort", properties, "80");
setIfUndefined("http.nonProxyHosts", properties, "localhost|127.*|[::1]");
}
if (getBoolean("https.proxy", properties)) {
setIfUndefined("https.proxyHost", properties, "");
setIfUndefined("https.proxyPort", properties, "443");
setIfUndefined("http.nonProxyHosts", properties, "localhost|127.*|[::1]");
}
if (getBoolean("socks.proxy", properties)) {
setIfUndefined("socksProxyHost", properties.getProperty("socks.proxyHost", ""));
setIfUndefined("socksProxyPort", properties.getProperty("socks.proxyPort", "1080"));
if (getBoolean("use.proxy", properties)) {
if (getBoolean("http.proxy", properties)) {
setIfUndefined("http.proxyHost", properties, "");
setIfUndefined("http.proxyPort", properties, "80");
setIfUndefined("http.nonProxyHosts", properties, "localhost|127.*|[::1]");
}
if (getBoolean("https.proxy", properties)) {
setIfUndefined("https.proxyHost", properties, "");
setIfUndefined("https.proxyPort", properties, "443");
setIfUndefined("http.nonProxyHosts", properties, "localhost|127.*|[::1]");
}
if (getBoolean("socks.proxy", properties)) {
setIfUndefined("socksProxyHost", properties.getProperty("socks.proxyHost", ""));
setIfUndefined("socksProxyPort", properties.getProperty("socks.proxyPort", "1080"));
}

int port = url.getPort();
if (port == -1) port = url.getDefaultPort();
return builder.proxy(ProxySelector.of(new InetSocketAddress(url.getHost(), port)));
}

int port = url.getPort();
if (port == -1) port = url.getDefaultPort();
return builder.proxy(ProxySelector.of(new InetSocketAddress(url.getHost(), port)));
return builder;
}

private static HttpClient.Builder setupAuthentication(HttpClient.Builder builder, URL url, Properties properties) {
Expand Down

0 comments on commit ddac9d0

Please sign in to comment.