Skip to content

Commit

Permalink
Get Config settings as Options to benefit from the defaults
Browse files Browse the repository at this point in the history
thanks to Bombe!

For #691
  • Loading branch information
ArneBab committed Nov 14, 2020
1 parent 6be95c3 commit 8af54a4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/freenet/clients/http/FProxyToadlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> headers = ctx.getHeaders();
Expand Down
15 changes: 7 additions & 8 deletions src/freenet/clients/http/utils/UriFilterProxyHeaderParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> headers;

public UriFilterProxyHeaderParser(
String fProxyPort,
String fProxyBindTo,
Option<?> fProxyPort,
Option<?> fProxyBindTo,
String uriScheme,
String uriHost,
MultiValueTable<String, String> headers
Expand All @@ -33,17 +34,15 @@ public UriFilterProxyHeaderParser(
public String getSchemeHostAndPort() {
Set<String> safeProtocols = new HashSet<>(Arrays.asList("http", "https"));

List<String> bindToHosts = Arrays.asList(fProxyBindToConfig.split(",")).stream()
List<String> bindToHosts = Arrays.stream(fProxyBindToConfig.getValueString().split(","))
.map(host -> host.contains(":") ? "[" + host + "]" : host)
.collect(Collectors.toList());
String firstBindToHost = bindToHosts.get(0);
// set default values
if (firstBindToHost.isEmpty()) {
firstBindToHost = "127.0.0.1";
}
String port = fProxyPortConfig.isEmpty()
? "8888"
: fProxyPortConfig;
String port = fProxyPortConfig.getValueString();
// allow all bindToHosts
Set<String> safeHosts = new HashSet<>(bindToHosts);
// also allow bindTo hosts with the fProxyPortConfig added
Expand Down

0 comments on commit 8af54a4

Please sign in to comment.