Merge branch '2.1.x'

This commit is contained in:
Andy Wilkinson 2019-02-11 17:12:51 +00:00
commit b5c9afc055
2 changed files with 17 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -37,6 +37,7 @@ import org.springframework.util.unit.DataSize;
* @author Yulin Qin * @author Yulin Qin
* @author Stephane Nicoll * @author Stephane Nicoll
* @author Phillip Webb * @author Phillip Webb
* @author Arstiom Yudovin
* @since 2.0.0 * @since 2.0.0
*/ */
public class UndertowWebServerFactoryCustomizer implements public class UndertowWebServerFactoryCustomizer implements
@ -106,7 +107,7 @@ public class UndertowWebServerFactoryCustomizer implements
private void customizeConnectionTimeout(ConfigurableUndertowWebServerFactory factory, private void customizeConnectionTimeout(ConfigurableUndertowWebServerFactory factory,
Duration connectionTimeout) { Duration connectionTimeout) {
factory.addBuilderCustomizers((builder) -> builder.setSocketOption( factory.addBuilderCustomizers((builder) -> builder.setServerOption(
UndertowOptions.NO_REQUEST_TIMEOUT, (int) connectionTimeout.toMillis())); UndertowOptions.NO_REQUEST_TIMEOUT, (int) connectionTimeout.toMillis()));
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2018 the original author or authors. * Copyright 2012-2019 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -47,6 +47,7 @@ import static org.mockito.Mockito.verify;
* *
* @author Brian Clozel * @author Brian Clozel
* @author Phillip Webb * @author Phillip Webb
* @author Artsiom Yudovin
*/ */
public class UndertowWebServerFactoryCustomizerTests { public class UndertowWebServerFactoryCustomizerTests {
@ -143,6 +144,18 @@ public class UndertowWebServerFactoryCustomizerTests {
assertThat(map.contains(UndertowOptions.MAX_HEADER_SIZE)).isFalse(); assertThat(map.contains(UndertowOptions.MAX_HEADER_SIZE)).isFalse();
} }
@Test
public void customConnectionTimeout() {
bind("server.connection-timeout=100");
Builder builder = Undertow.builder();
ConfigurableUndertowWebServerFactory factory = mockFactory(builder);
this.customizer.customize(factory);
OptionMap map = ((OptionMap.Builder) ReflectionTestUtils.getField(builder,
"serverOptions")).getMap();
assertThat(map.contains(UndertowOptions.NO_REQUEST_TIMEOUT)).isTrue();
assertThat(map.get(UndertowOptions.NO_REQUEST_TIMEOUT)).isEqualTo(100);
}
private ConfigurableUndertowWebServerFactory mockFactory(Builder builder) { private ConfigurableUndertowWebServerFactory mockFactory(Builder builder) {
ConfigurableUndertowWebServerFactory factory = mock( ConfigurableUndertowWebServerFactory factory = mock(
ConfigurableUndertowWebServerFactory.class); ConfigurableUndertowWebServerFactory.class);