mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Merge branch '2.2.x'
Closes gh-19529
This commit is contained in:
commit
bb55bad170
@ -85,7 +85,7 @@ public class ServerProperties {
|
||||
/**
|
||||
* Strategy for handling X-Forwarded-* headers.
|
||||
*/
|
||||
private ForwardHeadersStrategy forwardHeadersStrategy = ForwardHeadersStrategy.NONE;
|
||||
private ForwardHeadersStrategy forwardHeadersStrategy;
|
||||
|
||||
/**
|
||||
* Value to use for the Server response header (if empty, no header is sent).
|
||||
|
@ -102,7 +102,7 @@ public class JettyWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private boolean getOrDeduceUseForwardHeaders() {
|
||||
if (this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NONE)) {
|
||||
if (this.serverProperties.getForwardHeadersStrategy() == null) {
|
||||
CloudPlatform platform = CloudPlatform.getActive(this.environment);
|
||||
return platform != null && platform.isUsingForwardHeaders();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class NettyWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private boolean getOrDeduceUseForwardHeaders() {
|
||||
if (this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NONE)) {
|
||||
if (this.serverProperties.getForwardHeadersStrategy() == null) {
|
||||
CloudPlatform platform = CloudPlatform.getActive(this.environment);
|
||||
return platform != null && platform.isUsingForwardHeaders();
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ public class TomcatWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private boolean getOrDeduceUseForwardHeaders() {
|
||||
if (this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NONE)) {
|
||||
if (this.serverProperties.getForwardHeadersStrategy() == null) {
|
||||
CloudPlatform platform = CloudPlatform.getActive(this.environment);
|
||||
return platform != null && platform.isUsingForwardHeaders();
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class UndertowWebServerFactoryCustomizer
|
||||
}
|
||||
|
||||
private boolean getOrDeduceUseForwardHeaders() {
|
||||
if (this.serverProperties.getForwardHeadersStrategy().equals(ServerProperties.ForwardHeadersStrategy.NONE)) {
|
||||
if (this.serverProperties.getForwardHeadersStrategy() == null) {
|
||||
CloudPlatform platform = CloudPlatform.getActive(this.environment);
|
||||
return platform != null && platform.isUsingForwardHeaders();
|
||||
}
|
||||
|
@ -86,6 +86,23 @@ class JettyWebServerFactoryCustomizerTests {
|
||||
verify(factory).setUseForwardHeaders(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||
ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNoneShouldNotConfigureValve() {
|
||||
this.environment.setProperty("DYNO", "-");
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE);
|
||||
ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accessLogCanBeCustomized() throws IOException {
|
||||
File logFile = File.createTempFile("jetty_log", ".log");
|
||||
|
@ -92,6 +92,23 @@ class NettyWebServerFactoryCustomizerTests {
|
||||
verify(factory).setUseForwardHeaders(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNoneShouldNotConfigureValve() {
|
||||
this.environment.setProperty("DYNO", "-");
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE);
|
||||
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setServerConnectionTimeoutAsZero() {
|
||||
setupServerConnectionTimeout(Duration.ZERO);
|
||||
|
@ -259,6 +259,26 @@ class TomcatWebServerFactoryCustomizerTests {
|
||||
testRemoteIpValveConfigured();
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultUseForwardHeaders() {
|
||||
TomcatServletWebServerFactory factory = customizeAndGetFactory();
|
||||
assertThat(factory.getEngineValves()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||
testRemoteIpValveConfigured();
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNoneShouldNotConfigureValve() {
|
||||
this.environment.setProperty("DYNO", "-");
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE);
|
||||
TomcatServletWebServerFactory factory = customizeAndGetFactory();
|
||||
assertThat(factory.getEngineValves()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultRemoteIpValve() {
|
||||
// Since 1.1.7 you need to specify at least the protocol
|
||||
|
@ -202,6 +202,23 @@ class UndertowWebServerFactoryCustomizerTests {
|
||||
verify(factory).setUseForwardHeaders(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
|
||||
ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forwardHeadersWhenStrategyIsNoneShouldNotConfigureValve() {
|
||||
this.environment.setProperty("DYNO", "-");
|
||||
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NONE);
|
||||
ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class);
|
||||
this.customizer.customize(factory);
|
||||
verify(factory).setUseForwardHeaders(false);
|
||||
}
|
||||
|
||||
private <T> T boundServerOption(Option<T> option) {
|
||||
Builder builder = Undertow.builder();
|
||||
ConfigurableUndertowWebServerFactory factory = mockFactory(builder);
|
||||
|
Loading…
Reference in New Issue
Block a user