From 8af54a43fd8f40b81fc1265aac5510dae9eb163f Mon Sep 17 00:00:00 2001 From: Arne Babenhauserheide Date: Sat, 14 Nov 2020 16:17:46 +0100 Subject: [PATCH] Get Config settings as Options to benefit from the defaults thanks to Bombe! For https://github.com/freenet/fred/pull/691 --- src/freenet/clients/http/FProxyToadlet.java | 5 +++-- .../http/utils/UriFilterProxyHeaderParser.java | 15 +++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/freenet/clients/http/FProxyToadlet.java b/src/freenet/clients/http/FProxyToadlet.java index 34670eaa1ca..405190684d2 100644 --- a/src/freenet/clients/http/FProxyToadlet.java +++ b/src/freenet/clients/http/FProxyToadlet.java @@ -44,6 +44,7 @@ import freenet.clients.http.updateableelements.ProgressInfoElement; import freenet.clients.http.utils.UriFilterProxyHeaderParser; import freenet.config.Config; +import freenet.config.Option; import freenet.config.SubConfig; import freenet.crypt.SHA256; import freenet.keys.FreenetURI; @@ -991,8 +992,8 @@ private String getSchemeHostAndPort(ToadletContext ctx) { // retrieve config from froxy SubConfig fProxyConfig = core.node.config.get("fproxy"); - String fProxyPort = String.valueOf(fProxyConfig.getInt("port")); - String fProxyBindTo = fProxyConfig.getString("bindTo"); + Option fProxyPort = fProxyConfig.getOption("port"); + Option fProxyBindTo = fProxyConfig.getOption("bindTo"); // get uri host and headers MultiValueTable headers = ctx.getHeaders(); diff --git a/src/freenet/clients/http/utils/UriFilterProxyHeaderParser.java b/src/freenet/clients/http/utils/UriFilterProxyHeaderParser.java index c127994726b..440b3e3d2ee 100644 --- a/src/freenet/clients/http/utils/UriFilterProxyHeaderParser.java +++ b/src/freenet/clients/http/utils/UriFilterProxyHeaderParser.java @@ -6,18 +6,19 @@ import java.util.Set; import java.util.stream.Collectors; +import freenet.config.Option; import freenet.support.MultiValueTable; public class UriFilterProxyHeaderParser { - private final String fProxyPortConfig; - private final String fProxyBindToConfig; + private final Option fProxyPortConfig; + private final Option fProxyBindToConfig; private final String uriScheme; private final String uriHost; private final MultiValueTable headers; public UriFilterProxyHeaderParser( - String fProxyPort, - String fProxyBindTo, + Option fProxyPort, + Option fProxyBindTo, String uriScheme, String uriHost, MultiValueTable headers @@ -33,7 +34,7 @@ public UriFilterProxyHeaderParser( public String getSchemeHostAndPort() { Set safeProtocols = new HashSet<>(Arrays.asList("http", "https")); - List bindToHosts = Arrays.asList(fProxyBindToConfig.split(",")).stream() + List bindToHosts = Arrays.stream(fProxyBindToConfig.getValueString().split(",")) .map(host -> host.contains(":") ? "[" + host + "]" : host) .collect(Collectors.toList()); String firstBindToHost = bindToHosts.get(0); @@ -41,9 +42,7 @@ public String getSchemeHostAndPort() { if (firstBindToHost.isEmpty()) { firstBindToHost = "127.0.0.1"; } - String port = fProxyPortConfig.isEmpty() - ? "8888" - : fProxyPortConfig; + String port = fProxyPortConfig.getValueString(); // allow all bindToHosts Set safeHosts = new HashSet<>(bindToHosts); // also allow bindTo hosts with the fProxyPortConfig added