Polish "Allow Undertow's options to be configured via the environment
See gh-17356
This commit is contained in:
parent
417f4dd7fa
commit
3bd7760f9c
|
|
@ -142,12 +142,12 @@ public class UndertowWebServerFactoryCustomizer
|
||||||
return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
return this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private <T> void setCustomOption(ConfigurableUndertowWebServerFactory factory, String key, String value,
|
private <T> void setCustomOption(ConfigurableUndertowWebServerFactory factory, String key, String value,
|
||||||
String type) {
|
String type) {
|
||||||
Field[] fields = UndertowOptions.class.getDeclaredFields();
|
Field[] fields = UndertowOptions.class.getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
String name = getLetterAndNumber(key);
|
if (getCanonicalName(field.getName()).equals(getCanonicalName(key))) {
|
||||||
if (getLetterAndNumber(field.getName()).equals(name)) {
|
|
||||||
Option<T> option = (Option<T>) Option.fromString(
|
Option<T> option = (Option<T>) Option.fromString(
|
||||||
UndertowOptions.class.getName() + '.' + field.getName(), getClass().getClassLoader());
|
UndertowOptions.class.getName() + '.' + field.getName(), getClass().getClassLoader());
|
||||||
T parsed = option.parseValue(value, getClass().getClassLoader());
|
T parsed = option.parseValue(value, getClass().getClassLoader());
|
||||||
|
|
@ -162,9 +162,9 @@ public class UndertowWebServerFactoryCustomizer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getLetterAndNumber(String name) {
|
private String getCanonicalName(String key) {
|
||||||
StringBuilder canonicalName = new StringBuilder(name.length());
|
StringBuilder canonicalName = new StringBuilder(key.length());
|
||||||
name.chars().map((c) -> (char) c).filter(Character::isLetterOrDigit).map(Character::toLowerCase)
|
key.chars().map((c) -> (char) c).filter(Character::isLetterOrDigit).map(Character::toLowerCase)
|
||||||
.forEach((c) -> canonicalName.append((char) c));
|
.forEach((c) -> canonicalName.append((char) c));
|
||||||
return canonicalName.toString();
|
return canonicalName.toString();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,12 +161,23 @@ class UndertowWebServerFactoryCustomizerTests {
|
||||||
assertThat(boundServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
assertThat(boundServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void customServerOptionShouldBeRelaxed() {
|
||||||
|
bind("server.undertow.options.server.always-set-keep-alive=false");
|
||||||
|
assertThat(boundServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void customSocketOption() {
|
void customSocketOption() {
|
||||||
bind("server.undertow.options.socket.ALWAYS_SET_KEEP_ALIVE=false");
|
bind("server.undertow.options.socket.ALWAYS_SET_KEEP_ALIVE=false");
|
||||||
assertThat(boundSocketOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
assertThat(boundSocketOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void customSocketOptionShouldBeRelaxed() {
|
||||||
|
bind("server.undertow.options.socket.always-set-keep-alive=false");
|
||||||
|
assertThat(boundSocketOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE)).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deduceUseForwardHeaders() {
|
void deduceUseForwardHeaders() {
|
||||||
this.environment.setProperty("DYNO", "-");
|
this.environment.setProperty("DYNO", "-");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue