From 7f78b89cb8b4378946be4bebbb45a9521e345d05 Mon Sep 17 00:00:00 2001 From: nicolas Date: Mon, 4 Mar 2019 01:57:58 -0500 Subject: [PATCH 1/4] enable configuration of jetty's ncsa request log ignorePaths partially resolves GH-15677 --- .../boot/autoconfigure/web/ServerProperties.java | 16 ++++++++++++++-- .../JettyWebServerFactoryCustomizer.java | 3 +++ .../autoconfigure/web/ServerPropertiesTests.java | 5 +++++ .../JettyWebServerFactoryCustomizerTests.java | 12 ++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 682dda50c0d4..147267f25a36 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -309,8 +309,8 @@ public static class Tomcat { private File basedir; /** - * Delay between the invocation of backgroundProcess methods. If a duration suffix - * is not specified, seconds will be used. + * Delay between the invocation of backgroundProcess methods. If a duration suffix is not + * specified, seconds will be used. */ @DurationUnit(ChronoUnit.SECONDS) private Duration backgroundProcessorDelay = Duration.ofSeconds(10); @@ -846,6 +846,11 @@ public static class Accesslog { */ private boolean logLatency; + /** + * Set request paths that will not be logged. + */ + private List ignorePaths; + public boolean isEnabled() { return this.enabled; } @@ -942,6 +947,13 @@ public void setLogLatency(boolean logLatency) { this.logLatency = logLatency; } + public List getIgnorePaths() { + return ignorePaths; + } + + public void setIgnorePaths(List ignorePaths) { + this.ignorePaths = ignorePaths; + } } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index af50cb504800..5c06b02d6771 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -167,6 +167,9 @@ private void customizeAccessLog(ConfigurableJettyWebServerFactory factory, if (properties.getTimeZone() != null) { log.setLogTimeZone(properties.getTimeZone().getID()); } + if (properties.getIgnorePaths() != null) { + log.setIgnorePaths(properties.getIgnorePaths().toArray(new String[0])); + } log.setLogCookies(properties.isLogCookies()); log.setLogServer(properties.isLogServer()); log.setLogLatency(properties.isLogLatency()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index d09db2f56e00..c3b68805615f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -190,6 +190,8 @@ public void testCustomizeJettyAccessLog() { map.put("server.jetty.accesslog.file-date-format", "yyyymmdd"); map.put("server.jetty.accesslog.retention-period", "4"); map.put("server.jetty.accesslog.append", "true"); + map.put("server.jetty.accesslog.ignore-paths[0]", "/a/path"); + map.put("server.jetty.accesslog.ignore-paths[1]", "/b/path"); bind(map); ServerProperties.Jetty jetty = this.properties.getJetty(); assertThat(jetty.getAccesslog().isEnabled()).isTrue(); @@ -197,6 +199,9 @@ public void testCustomizeJettyAccessLog() { assertThat(jetty.getAccesslog().getFileDateFormat()).isEqualTo("yyyymmdd"); assertThat(jetty.getAccesslog().getRetentionPeriod()).isEqualTo(4); assertThat(jetty.getAccesslog().isAppend()).isTrue(); + assertThat(jetty.getAccesslog().getIgnorePaths().size()).isEqualTo(2); + assertThat(jetty.getAccesslog().getIgnorePaths().get(0)).isEqualTo("/a/path"); + assertThat(jetty.getAccesslog().getIgnorePaths().get(1)).isEqualTo("/b/path"); } @Test diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java index 30920afb8175..d3eb835a1dea 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java @@ -117,6 +117,18 @@ public void accessLogCanBeCustomized() throws IOException { assertThat(requestLog.getLogLatency()).isTrue(); } + @Test + public void canSetIgnorePaths() { + bind("server.jetty.accesslog.enabled=true", + "server.jetty.accesslog.ignore-paths[0]=/a/path", + "server.jetty.accesslog.ignore-paths[1]=/b/path"); + JettyWebServer server = customizeAndGetServer(); + NCSARequestLog requestLog = getNCSARequestLog(server); + assertThat(requestLog.getIgnorePaths().length).isEqualTo(2); + assertThat(requestLog.getIgnorePaths()[0]).isEqualTo("/a/path"); + assertThat(requestLog.getIgnorePaths()[1]).isEqualTo("/b/path"); + } + @Test public void accessLogCanBeEnabled() { bind("server.jetty.accesslog.enabled=true"); From 8a09b5fe600b1d1235bdbf9d79da8bc842a85ea7 Mon Sep 17 00:00:00 2001 From: nicolas Date: Mon, 4 Mar 2019 01:58:29 -0500 Subject: [PATCH 2/4] enable configuration of jetty's ncsa request log ignorePaths partially resolves GH-15677 --- .../autoconfigure/web/ServerProperties.java | 68 +++++++++---------- .../JettyWebServerFactoryCustomizer.java | 2 - .../web/ServerPropertiesTests.java | 9 +-- .../JettyWebServerFactoryCustomizerTests.java | 10 ++- 4 files changed, 40 insertions(+), 49 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 147267f25a36..d5ac35e8bc5c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -90,9 +90,9 @@ public class ServerProperties { private DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8); /** - * Time that connectors wait for another HTTP request before closing the connection. - * When not set, the connector's container-specific default is used. Use a value of -1 - * to indicate no (that is, an infinite) timeout. + * Time that connectors wait for another HTTP request before closing the connection. When not set, + * the connector's container-specific default is used. Use a value of -1 to indicate no (that is, + * an infinite) timeout. */ private Duration connectionTimeout; @@ -341,14 +341,13 @@ public static class Tomcat { private DataSize maxSwallowSize = DataSize.ofMegabytes(2); /** - * Whether requests to the context root should be redirected by appending a / to - * the path. + * Whether requests to the context root should be redirected by appending a / to the path. */ private Boolean redirectContextRoot = true; /** - * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect - * will use relative or absolute redirects. + * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect will use + * relative or absolute redirects. */ private Boolean useRelativeRedirects; @@ -358,28 +357,28 @@ public static class Tomcat { private Charset uriEncoding = StandardCharsets.UTF_8; /** - * Maximum number of connections that the server accepts and processes at any - * given time. Once the limit has been reached, the operating system may still - * accept connections based on the "acceptCount" property. + * Maximum number of connections that the server accepts and processes at any given time. Once + * the limit has been reached, the operating system may still accept connections based on the + * "acceptCount" property. */ private int maxConnections = 10000; /** - * Maximum queue length for incoming connection requests when all possible request - * processing threads are in use. + * Maximum queue length for incoming connection requests when all possible request processing + * threads are in use. */ private int acceptCount = 100; /** - * Maximum number of idle processors that will be retained in the cache and reused - * with a subsequent request. + * Maximum number of idle processors that will be retained in the cache and reused with a + * subsequent request. */ private int processorCache = 200; /** - * Comma-separated list of additional patterns that match jars to ignore for TLD - * scanning. The special '?' and '*' characters can be used in the pattern to - * match one and only one character and zero or more characters respectively. + * Comma-separated list of additional patterns that match jars to ignore for TLD scanning. The + * special '?' and '*' characters can be used in the pattern to match one and only one character + * and zero or more characters respectively. */ private List additionalTldSkipPatterns = new ArrayList<>(); @@ -567,8 +566,8 @@ public static class Accesslog { private String pattern = "common"; /** - * Directory in which log files are created. Can be absolute or relative to - * the Tomcat base dir. + * Directory in which log files are created. Can be absolute or relative to the Tomcat base + * dir. */ private String directory = "logs"; @@ -588,8 +587,7 @@ public static class Accesslog { private boolean rotate = true; /** - * Whether to defer inclusion of the date stamp in the file name until rotate - * time. + * Whether to defer inclusion of the date stamp in the file name until rotate time. */ private boolean renameOnRotate = false; @@ -599,8 +597,8 @@ public static class Accesslog { private String fileDateFormat = ".yyyy-MM-dd"; /** - * Set request attributes for the IP address, Hostname, protocol, and port - * used for the request. + * Set request attributes for the IP address, Hostname, protocol, and port used for the + * request. */ private boolean requestAttributesEnabled = false; @@ -742,14 +740,14 @@ public static class Jetty { private DataSize maxHttpPostSize = DataSize.ofBytes(200000); /** - * Number of acceptor threads to use. When the value is -1, the default, the - * number of acceptors is derived from the operating environment. + * Number of acceptor threads to use. When the value is -1, the default, the number of acceptors + * is derived from the operating environment. */ private Integer acceptors = -1; /** - * Number of selector threads to use. When the value is -1, the default, the - * number of selectors is derived from the operating environment. + * Number of selector threads to use. When the value is -1, the default, the number of selectors + * is derived from the operating environment. */ private Integer selectors = -1; @@ -964,20 +962,20 @@ public void setIgnorePaths(List ignorePaths) { public static class Undertow { /** - * Maximum size of the HTTP post content. When the value is -1, the default, the - * size is unlimited. + * Maximum size of the HTTP post content. When the value is -1, the default, the size is + * unlimited. */ private DataSize maxHttpPostSize = DataSize.ofBytes(-1); /** - * Size of each buffer. The default is derived from the maximum amount of memory - * that is available to the JVM. + * Size of each buffer. The default is derived from the maximum amount of memory that is + * available to the JVM. */ private DataSize bufferSize; /** - * Number of I/O threads to create for the worker. The default is derived from the - * number of available processors. + * Number of I/O threads to create for the worker. The default is derived from the number of + * available processors. */ private Integer ioThreads; @@ -987,8 +985,8 @@ public static class Undertow { private Integer workerThreads; /** - * Whether to allocate buffers outside the Java heap. The default is derived from - * the maximum amount of memory that is available to the JVM. + * Whether to allocate buffers outside the Java heap. The default is derived from the maximum + * amount of memory that is available to the JVM. */ private Boolean directBuffers; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index 5c06b02d6771..a69d0ec653e0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -18,7 +18,6 @@ import java.time.Duration; import java.util.Arrays; - import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.Handler; @@ -28,7 +27,6 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; - import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.cloud.CloudPlatform; import org.springframework.boot.context.properties.PropertyMapper; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index c3b68805615f..82de25aaf2ee 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -16,6 +16,9 @@ package org.springframework.boot.autoconfigure.web; +import static org.assertj.core.api.Assertions.assertThat; + +import io.undertow.UndertowOptions; import java.io.IOException; import java.net.InetAddress; import java.net.URI; @@ -25,13 +28,10 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; - import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import io.undertow.UndertowOptions; import org.apache.catalina.connector.Connector; import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardEngine; @@ -41,7 +41,6 @@ import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; import org.junit.Test; - import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; @@ -60,8 +59,6 @@ import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; -import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for {@link ServerProperties}. * diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java index d3eb835a1dea..e35e3790b1d4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java @@ -16,13 +16,16 @@ package org.springframework.boot.autoconfigure.web.embedded; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.TimeZone; - import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration.ConnectionFactory; @@ -30,7 +33,6 @@ import org.eclipse.jetty.server.RequestLog; import org.junit.Before; import org.junit.Test; - import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; @@ -41,10 +43,6 @@ import org.springframework.mock.env.MockEnvironment; import org.springframework.test.context.support.TestPropertySourceUtils; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - /** * Tests for {@link JettyWebServerFactoryCustomizer}. * From e9ed562784d113214910437801df2b01ce1289fd Mon Sep 17 00:00:00 2001 From: nicolas Date: Mon, 4 Mar 2019 02:04:04 -0500 Subject: [PATCH 3/4] revert some auto formatting from IDE --- .../autoconfigure/web/ServerProperties.java | 72 ++++++++++--------- .../JettyWebServerFactoryCustomizer.java | 2 + .../web/ServerPropertiesTests.java | 9 ++- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index d5ac35e8bc5c..c3f5900752ed 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -90,9 +90,9 @@ public class ServerProperties { private DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8); /** - * Time that connectors wait for another HTTP request before closing the connection. When not set, - * the connector's container-specific default is used. Use a value of -1 to indicate no (that is, - * an infinite) timeout. + * Time that connectors wait for another HTTP request before closing the connection. + * When not set, the connector's container-specific default is used. Use a value of -1 + * to indicate no (that is, an infinite) timeout. */ private Duration connectionTimeout; @@ -309,8 +309,8 @@ public static class Tomcat { private File basedir; /** - * Delay between the invocation of backgroundProcess methods. If a duration suffix is not - * specified, seconds will be used. + * Delay between the invocation of backgroundProcess methods. If a duration suffix + * is not specified, seconds will be used. */ @DurationUnit(ChronoUnit.SECONDS) private Duration backgroundProcessorDelay = Duration.ofSeconds(10); @@ -341,13 +341,14 @@ public static class Tomcat { private DataSize maxSwallowSize = DataSize.ofMegabytes(2); /** - * Whether requests to the context root should be redirected by appending a / to the path. + * Whether requests to the context root should be redirected by appending a / to + * the path. */ private Boolean redirectContextRoot = true; /** - * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect will use - * relative or absolute redirects. + * Whether HTTP 1.1 and later location headers generated by a call to sendRedirect + * will use relative or absolute redirects. */ private Boolean useRelativeRedirects; @@ -357,28 +358,28 @@ public static class Tomcat { private Charset uriEncoding = StandardCharsets.UTF_8; /** - * Maximum number of connections that the server accepts and processes at any given time. Once - * the limit has been reached, the operating system may still accept connections based on the - * "acceptCount" property. + * Maximum number of connections that the server accepts and processes at any + * given time. Once the limit has been reached, the operating system may still + * accept connections based on the "acceptCount" property. */ private int maxConnections = 10000; /** - * Maximum queue length for incoming connection requests when all possible request processing - * threads are in use. + * Maximum queue length for incoming connection requests when all possible request + * processing threads are in use. */ private int acceptCount = 100; /** - * Maximum number of idle processors that will be retained in the cache and reused with a - * subsequent request. + * Maximum number of idle processors that will be retained in the cache and reused + * with a subsequent request. */ private int processorCache = 200; /** - * Comma-separated list of additional patterns that match jars to ignore for TLD scanning. The - * special '?' and '*' characters can be used in the pattern to match one and only one character - * and zero or more characters respectively. + * Comma-separated list of additional patterns that match jars to ignore for TLD + * scanning. The special '?' and '*' characters can be used in the pattern to + * match one and only one character and zero or more characters respectively. */ private List additionalTldSkipPatterns = new ArrayList<>(); @@ -566,8 +567,8 @@ public static class Accesslog { private String pattern = "common"; /** - * Directory in which log files are created. Can be absolute or relative to the Tomcat base - * dir. + * Directory in which log files are created. Can be absolute or relative to + * the Tomcat base dir. */ private String directory = "logs"; @@ -587,7 +588,8 @@ public static class Accesslog { private boolean rotate = true; /** - * Whether to defer inclusion of the date stamp in the file name until rotate time. + * Whether to defer inclusion of the date stamp in the file name until rotate + * time. */ private boolean renameOnRotate = false; @@ -597,8 +599,8 @@ public static class Accesslog { private String fileDateFormat = ".yyyy-MM-dd"; /** - * Set request attributes for the IP address, Hostname, protocol, and port used for the - * request. + * Set request attributes for the IP address, Hostname, protocol, and port + * used for the request. */ private boolean requestAttributesEnabled = false; @@ -740,14 +742,14 @@ public static class Jetty { private DataSize maxHttpPostSize = DataSize.ofBytes(200000); /** - * Number of acceptor threads to use. When the value is -1, the default, the number of acceptors - * is derived from the operating environment. + * Number of acceptor threads to use. When the value is -1, the default, the + * number of acceptors is derived from the operating environment. */ private Integer acceptors = -1; /** - * Number of selector threads to use. When the value is -1, the default, the number of selectors - * is derived from the operating environment. + * Number of selector threads to use. When the value is -1, the default, the + * number of selectors is derived from the operating environment. */ private Integer selectors = -1; @@ -962,20 +964,20 @@ public void setIgnorePaths(List ignorePaths) { public static class Undertow { /** - * Maximum size of the HTTP post content. When the value is -1, the default, the size is - * unlimited. + * Maximum size of the HTTP post content. When the value is -1, the default, the + * size is unlimited. */ private DataSize maxHttpPostSize = DataSize.ofBytes(-1); /** - * Size of each buffer. The default is derived from the maximum amount of memory that is - * available to the JVM. + * Size of each buffer. The default is derived from the maximum amount of memory + * that is available to the JVM. */ private DataSize bufferSize; /** - * Number of I/O threads to create for the worker. The default is derived from the number of - * available processors. + * Number of I/O threads to create for the worker. The default is derived from the + * number of available processors. */ private Integer ioThreads; @@ -985,8 +987,8 @@ public static class Undertow { private Integer workerThreads; /** - * Whether to allocate buffers outside the Java heap. The default is derived from the maximum - * amount of memory that is available to the JVM. + * Whether to allocate buffers outside the Java heap. The default is derived from + * the maximum amount of memory that is available to the JVM. */ private Boolean directBuffers; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index a69d0ec653e0..5c06b02d6771 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -18,6 +18,7 @@ import java.time.Duration; import java.util.Arrays; + import org.eclipse.jetty.server.AbstractConnector; import org.eclipse.jetty.server.ConnectionFactory; import org.eclipse.jetty.server.Handler; @@ -27,6 +28,7 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; + import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.cloud.CloudPlatform; import org.springframework.boot.context.properties.PropertyMapper; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 82de25aaf2ee..c3b68805615f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -16,9 +16,6 @@ package org.springframework.boot.autoconfigure.web; -import static org.assertj.core.api.Assertions.assertThat; - -import io.undertow.UndertowOptions; import java.io.IOException; import java.net.InetAddress; import java.net.URI; @@ -28,10 +25,13 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import io.undertow.UndertowOptions; import org.apache.catalina.connector.Connector; import org.apache.catalina.core.StandardContext; import org.apache.catalina.core.StandardEngine; @@ -41,6 +41,7 @@ import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; import org.junit.Test; + import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; @@ -59,6 +60,8 @@ import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link ServerProperties}. * From f907fb51d57dc878cc52065dee975db4e465c904 Mon Sep 17 00:00:00 2001 From: nicolas Date: Mon, 18 Mar 2019 22:12:40 -0400 Subject: [PATCH 4/4] add prefer proxied for address --- .../autoconfigure/web/ServerProperties.java | 13 +++++++++++++ .../JettyWebServerFactoryCustomizer.java | 1 + .../JettyWebServerFactoryCustomizerTests.java | 17 +++++++---------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index c3f5900752ed..3c289619bacc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -851,6 +851,11 @@ public static class Accesslog { */ private List ignorePaths; + /** + * true - IP address from header will be logged, false - IP address from the connection will be logged + */ + private boolean preferProxiedForAddress = false; + public boolean isEnabled() { return this.enabled; } @@ -954,6 +959,14 @@ public List getIgnorePaths() { public void setIgnorePaths(List ignorePaths) { this.ignorePaths = ignorePaths; } + + public boolean getPreferProxiedForAddress(){ + return preferProxiedForAddress; + } + + public void setPreferProxiedForAddress(boolean preferProxiedForAddress){ + this.preferProxiedForAddress = preferProxiedForAddress; + } } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java index 5c06b02d6771..b97c2faf8df0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java @@ -173,6 +173,7 @@ private void customizeAccessLog(ConfigurableJettyWebServerFactory factory, log.setLogCookies(properties.isLogCookies()); log.setLogServer(properties.isLogServer()); log.setLogLatency(properties.isLogLatency()); + log.setPreferProxiedForAddress(properties.getPreferProxiedForAddress()); server.setRequestLog(log); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java index e35e3790b1d4..f414fe967a3d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizerTests.java @@ -99,7 +99,10 @@ public void accessLogCanBeCustomized() throws IOException { "server.jetty.accesslog.time-zone=" + timezone, "server.jetty.accesslog.log-cookies=true", "server.jetty.accesslog.log-server=true", - "server.jetty.accesslog.log-latency=true"); + "server.jetty.accesslog.log-latency=true", + "server.jetty.accesslog.prefer-proxied-for-address=true", + "server.jetty.accesslog.ignore-paths[0]=/a/path", + "server.jetty.accesslog.ignore-paths[1]=/b/path"); JettyWebServer server = customizeAndGetServer(); NCSARequestLog requestLog = getNCSARequestLog(server); assertThat(requestLog.getFilename()).isEqualTo(logFile.getAbsolutePath()); @@ -113,15 +116,7 @@ public void accessLogCanBeCustomized() throws IOException { assertThat(requestLog.getLogCookies()).isTrue(); assertThat(requestLog.getLogServer()).isTrue(); assertThat(requestLog.getLogLatency()).isTrue(); - } - - @Test - public void canSetIgnorePaths() { - bind("server.jetty.accesslog.enabled=true", - "server.jetty.accesslog.ignore-paths[0]=/a/path", - "server.jetty.accesslog.ignore-paths[1]=/b/path"); - JettyWebServer server = customizeAndGetServer(); - NCSARequestLog requestLog = getNCSARequestLog(server); + assertThat(requestLog.getPreferProxiedForAddress()).isTrue(); assertThat(requestLog.getIgnorePaths().length).isEqualTo(2); assertThat(requestLog.getIgnorePaths()[0]).isEqualTo("/a/path"); assertThat(requestLog.getIgnorePaths()[1]).isEqualTo("/b/path"); @@ -138,6 +133,8 @@ public void accessLogCanBeEnabled() { assertThat(requestLog.getLogCookies()).isFalse(); assertThat(requestLog.getLogServer()).isFalse(); assertThat(requestLog.getLogLatency()).isFalse(); + assertThat(requestLog.getIgnorePaths().length).isZero(); + assertThat(requestLog.getPreferProxiedForAddress()).isFalse(); } private NCSARequestLog getNCSARequestLog(JettyWebServer server) {