Commit ea44ae6a authored by Phillip Webb's avatar Phillip Webb

Polish contribution

parent 6d2f88ed
...@@ -32,7 +32,6 @@ import javax.validation.constraints.NotNull; ...@@ -32,7 +32,6 @@ import javax.validation.constraints.NotNull;
import io.undertow.Undertow.Builder; import io.undertow.Undertow.Builder;
import io.undertow.UndertowOptions; import io.undertow.UndertowOptions;
import org.apache.catalina.Context; import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector; import org.apache.catalina.connector.Connector;
import org.apache.catalina.valves.AccessLogValve; import org.apache.catalina.valves.AccessLogValve;
...@@ -655,10 +654,11 @@ public class ServerProperties ...@@ -655,10 +654,11 @@ public class ServerProperties
/** /**
* Get the max http header size. * Get the max http header size.
* @return the max http header size. * @return the max http header size.
* @deprecated in favor of {@code server.maxHttpHeaderSize} * @deprecated as of 1.4 in favor of
* {@link ServerProperties#getMaxHttpHeaderSize()}
*/ */
@Deprecated @Deprecated
@DeprecatedConfigurationProperty(replacement = "server.maxHttpHeaderSize") @DeprecatedConfigurationProperty(replacement = "server.max-http-header-size")
public int getMaxHttpHeaderSize() { public int getMaxHttpHeaderSize() {
return this.maxHttpHeaderSize; return this.maxHttpHeaderSize;
} }
...@@ -666,7 +666,8 @@ public class ServerProperties ...@@ -666,7 +666,8 @@ public class ServerProperties
/** /**
* Set the max http header size. * Set the max http header size.
* @param maxHttpHeaderSize the max http header size. * @param maxHttpHeaderSize the max http header size.
* @deprecated in favor of {@code server.maxHttpHeaderSize} * @deprecated as of 1.4 in favor of
* {@link ServerProperties#setMaxHttpHeaderSize(int)}
*/ */
@Deprecated @Deprecated
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) { public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
...@@ -754,11 +755,10 @@ public class ServerProperties ...@@ -754,11 +755,10 @@ public class ServerProperties
if (this.minSpareThreads > 0) { if (this.minSpareThreads > 0) {
customizeMinThreads(factory); customizeMinThreads(factory);
} }
if (serverProperties.getMaxHttpHeaderSize() > 0) { int maxHttpHeaderSize = (serverProperties.getMaxHttpHeaderSize() > 0
customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize()); ? serverProperties.getMaxHttpHeaderSize() : this.maxHttpHeaderSize);
} if (maxHttpHeaderSize > 0) {
else if (this.maxHttpHeaderSize > 0) { customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize);
customizeMaxHttpHeaderSize(factory, this.maxHttpHeaderSize);
} }
if (serverProperties.getMaxHttpPostSize() > 0) { if (serverProperties.getMaxHttpPostSize() > 0) {
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize()); customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
...@@ -841,7 +841,8 @@ public class ServerProperties ...@@ -841,7 +841,8 @@ public class ServerProperties
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
private void customizeMaxHttpHeaderSize( private void customizeMaxHttpHeaderSize(
TomcatEmbeddedServletContainerFactory factory, final int maxHttpHeaderSize) { TomcatEmbeddedServletContainerFactory factory,
final int maxHttpHeaderSize) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override @Override
...@@ -857,12 +858,15 @@ public class ServerProperties ...@@ -857,12 +858,15 @@ public class ServerProperties
} }
private void customizeMaxHttpPostSize( private void customizeMaxHttpPostSize(
TomcatEmbeddedServletContainerFactory factory, final int maxHttpPostSize) { TomcatEmbeddedServletContainerFactory factory,
final int maxHttpPostSize) {
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override @Override
public void customize(Connector connector) { public void customize(Connector connector) {
connector.setMaxPostSize(maxHttpPostSize); connector.setMaxPostSize(maxHttpPostSize);
} }
}); });
} }
...@@ -952,7 +956,8 @@ public class ServerProperties ...@@ -952,7 +956,8 @@ public class ServerProperties
JettyEmbeddedServletContainerFactory factory) { JettyEmbeddedServletContainerFactory factory) {
factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders()); factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
if (serverProperties.getMaxHttpHeaderSize() > 0) { if (serverProperties.getMaxHttpHeaderSize() > 0) {
customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize()); customizeMaxHttpHeaderSize(factory,
serverProperties.getMaxHttpHeaderSize());
} }
if (serverProperties.getMaxHttpPostSize() > 0) { if (serverProperties.getMaxHttpPostSize() > 0) {
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize()); customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
...@@ -960,23 +965,31 @@ public class ServerProperties ...@@ -960,23 +965,31 @@ public class ServerProperties
} }
private void customizeMaxHttpHeaderSize( private void customizeMaxHttpHeaderSize(
JettyEmbeddedServletContainerFactory factory, final int maxHttpHeaderSize) { JettyEmbeddedServletContainerFactory factory,
final int maxHttpHeaderSize) {
factory.addServerCustomizers(new JettyServerCustomizer() { factory.addServerCustomizers(new JettyServerCustomizer() {
@Override @Override
public void customize(Server server) { public void customize(Server server) {
org.eclipse.jetty.server.Connector[] connectors = server.getConnectors(); for (org.eclipse.jetty.server.Connector connector : server
for (org.eclipse.jetty.server.Connector connector : connectors) { .getConnectors()) {
for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) { for (ConnectionFactory connectionFactory : connector
.getConnectionFactories()) {
if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) {
HttpConfiguration httpConfig = customize(
((HttpConfiguration.ConnectionFactory) connectionFactory) (HttpConfiguration.ConnectionFactory) connectionFactory);
.getHttpConfiguration();
httpConfig.setRequestHeaderSize(maxHttpHeaderSize);
httpConfig.setResponseHeaderSize(maxHttpHeaderSize);
} }
} }
} }
} }
private void customize(HttpConfiguration.ConnectionFactory factory) {
HttpConfiguration configuration = factory.getHttpConfiguration();
configuration.setRequestHeaderSize(maxHttpHeaderSize);
configuration.setResponseHeaderSize(maxHttpHeaderSize);
}
}); });
} }
...@@ -993,7 +1006,8 @@ public class ServerProperties ...@@ -993,7 +1006,8 @@ public class ServerProperties
Handler... handlers) { Handler... handlers) {
for (Handler handler : handlers) { for (Handler handler : handlers) {
if (handler instanceof ContextHandler) { if (handler instanceof ContextHandler) {
((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize); ((ContextHandler) handler)
.setMaxFormContentSize(maxHttpPostSize);
} }
else if (handler instanceof HandlerWrapper) { else if (handler instanceof HandlerWrapper) {
setHandlerMaxHttpPostSize(maxHttpPostSize, setHandlerMaxHttpPostSize(maxHttpPostSize,
...@@ -1112,7 +1126,8 @@ public class ServerProperties ...@@ -1112,7 +1126,8 @@ public class ServerProperties
} }
factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders()); factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
if (serverProperties.getMaxHttpHeaderSize() > 0) { if (serverProperties.getMaxHttpHeaderSize() > 0) {
customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize()); customizeMaxHttpHeaderSize(factory,
serverProperties.getMaxHttpHeaderSize());
} }
if (serverProperties.getMaxHttpPostSize() > 0) { if (serverProperties.getMaxHttpPostSize() > 0) {
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize()); customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
...@@ -1120,22 +1135,30 @@ public class ServerProperties ...@@ -1120,22 +1135,30 @@ public class ServerProperties
} }
private void customizeMaxHttpHeaderSize( private void customizeMaxHttpHeaderSize(
UndertowEmbeddedServletContainerFactory factory, final int maxHttpHeaderSize) { UndertowEmbeddedServletContainerFactory factory,
final int maxHttpHeaderSize) {
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override @Override
public void customize(Builder builder) { public void customize(Builder builder) {
builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE, maxHttpHeaderSize); builder.setServerOption(UndertowOptions.MAX_HEADER_SIZE,
maxHttpHeaderSize);
} }
}); });
} }
private void customizeMaxHttpPostSize( private void customizeMaxHttpPostSize(
UndertowEmbeddedServletContainerFactory factory, final int maxHttpPostSize) { UndertowEmbeddedServletContainerFactory factory,
final int maxHttpPostSize) {
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() { factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override @Override
public void customize(Builder builder) { public void customize(Builder builder) {
builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, (long) maxHttpPostSize); builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE,
(long) maxHttpPostSize);
} }
}); });
} }
......
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.web;
import org.springframework.util.Assert;
/**
* A size threshold that can be specified in
*
* @author Phillip Webb
*/
class SizeThreshold {
private long inBytes;
private SizeThreshold(long inBytes) {
this.inBytes = inBytes;
}
public long getInBytes() {
return this.inBytes;
}
private static SizeThreshold parse(String size) {
Assert.hasLength(size, "Size must not be empty");
size = size.toUpperCase();
if (size.endsWith("KB")) {
return new SizeThreshold(
Long.valueOf(size.substring(0, size.length() - 2)) * 1024);
}
if (size.endsWith("MB")) {
return new SizeThreshold(
Long.valueOf(size.substring(0, size.length() - 2)) * 1024 * 1024);
}
return new SizeThreshold(Long.valueOf(size));
}
}
...@@ -253,11 +253,11 @@ public class ServerPropertiesTests { ...@@ -253,11 +253,11 @@ public class ServerPropertiesTests {
} }
@Test @Test
public void testCustomizeTomcatHeaderSize() throws Exception { public void testCustomizeHeaderSize() throws Exception {
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
map.put("server.tomcat.maxHttpHeaderSize", "9999"); map.put("server.maxHttpHeaderSize", "9999");
bindProperties(map); bindProperties(map);
assertThat(this.properties.getTomcat().getMaxHttpHeaderSize()).isEqualTo(9999); assertThat(this.properties.getMaxHttpHeaderSize()).isEqualTo(9999);
} }
@Test @Test
......
...@@ -159,6 +159,8 @@ content into your application; rather pick only the properties that you need. ...@@ -159,6 +159,8 @@ content into your application; rather pick only the properties that you need.
server.context-parameters.*= # Servlet context init parameters. For instance `server.context-parameters.a=alpha` server.context-parameters.*= # Servlet context init parameters. For instance `server.context-parameters.a=alpha`
server.context-path= # Context path of the application. server.context-path= # Context path of the application.
server.display-name=application # Display name of the application. server.display-name=application # Display name of the application.
server.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
server.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
server.error.include-stacktrace=never # When to include a "stacktrace" attribute. server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
server.error.path=/error # Path of the error controller. server.error.path=/error # Path of the error controller.
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error. server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
...@@ -168,6 +170,7 @@ content into your application; rather pick only the properties that you need. ...@@ -168,6 +170,7 @@ content into your application; rather pick only the properties that you need.
server.port=8080 # Server HTTP port. server.port=8080 # Server HTTP port.
server.server-header= # The value sent in the server response header (uses servlet container default if empty) server.server-header= # The value sent in the server response header (uses servlet container default if empty)
server.servlet-path=/ # Path of the main dispatcher servlet. server.servlet-path=/ # Path of the main dispatcher servlet.
server.use-forward-headers= # If X-Forwarded-* headers should be applied to the HttpRequest.
server.session.cookie.comment= # Comment for the session cookie. server.session.cookie.comment= # Comment for the session cookie.
server.session.cookie.domain= # Domain for the session cookie. server.session.cookie.domain= # Domain for the session cookie.
server.session.cookie.http-only= # "HttpOnly" flag for the session cookie. server.session.cookie.http-only= # "HttpOnly" flag for the session cookie.
...@@ -207,7 +210,6 @@ content into your application; rather pick only the properties that you need. ...@@ -207,7 +210,6 @@ content into your application; rather pick only the properties that you need.
172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\ 172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\ 172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses. 172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
server.tomcat.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
server.tomcat.max-threads=0 # Maximum amount of worker threads. server.tomcat.max-threads=0 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads. server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value. server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
...@@ -223,7 +225,6 @@ content into your application; rather pick only the properties that you need. ...@@ -223,7 +225,6 @@ content into your application; rather pick only the properties that you need.
server.undertow.direct-buffers= # Allocate buffers outside the Java heap. server.undertow.direct-buffers= # Allocate buffers outside the Java heap.
server.undertow.io-threads= # Number of I/O threads to create for the worker. server.undertow.io-threads= # Number of I/O threads to create for the worker.
server.undertow.worker-threads= # Number of worker threads. server.undertow.worker-threads= # Number of worker threads.
server.use-forward-headers= # If X-Forwarded-* headers should be applied to the HttpRequest.
# FREEMARKER ({sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration]) # FREEMARKER ({sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration])
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name. spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment