Skip to content

Commit

Permalink
Allow using single star for parts of domains in virtual host config
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Jan 8, 2024
1 parent aac6cab commit 05028d1
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,36 @@ public boolean virtualHostTestMode() {
return this.virtualHostTestMode;
}

public @Nullable String findConfigStringForHost(final @NonNull String host) {
return this.virtualHostConfigs.get(host.toLowerCase(Locale.ENGLISH));
public @Nullable String findConfigStringForHost(@NonNull String host) {
host = host.toLowerCase(Locale.ENGLISH);

final @Nullable String exactMatch = this.virtualHostConfigs.get(host);
if (exactMatch != null) {
return exactMatch;
}

configs:
for (final Map.Entry<String, String> e : this.virtualHostConfigs.entrySet()) {
final String key = e.getKey();
final String configName = e.getValue();
if (!key.contains("*")) {
continue;
}
final String[] splitKey = key.split("\\.");
final String[] splitHost = host.split("\\.");
if (splitKey.length != splitHost.length) {
continue;
}
for (int i = 0; i < splitHost.length; i++) {
final String keyPart = splitKey[i];
if (!keyPart.equals(splitHost[i]) && !keyPart.equals("*")) {
continue configs;
}
}
return configName;
}

return null;
}
}

Expand Down

0 comments on commit 05028d1

Please sign in to comment.