Polish “Allow connection timeout to be configured via the environment”
- Preserve default connection timeout when server.connection-timeout has not been set - Apply standard coding conventions and formatting See gh-6072
This commit is contained in:
@@ -30,7 +30,6 @@ import javax.servlet.SessionCookieConfig;
|
||||
import javax.servlet.SessionTrackingMode;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import io.undertow.Undertow;
|
||||
import io.undertow.Undertow.Builder;
|
||||
import io.undertow.UndertowOptions;
|
||||
import org.apache.catalina.Context;
|
||||
@@ -40,11 +39,11 @@ import org.apache.catalina.valves.RemoteIpValve;
|
||||
import org.apache.coyote.AbstractProtocol;
|
||||
import org.apache.coyote.ProtocolHandler;
|
||||
import org.apache.coyote.http11.AbstractHttp11Protocol;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.ConnectionFactory;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerWrapper;
|
||||
@@ -148,11 +147,11 @@ public class ServerProperties
|
||||
private int maxHttpPostSize = 0; // bytes
|
||||
|
||||
/**
|
||||
* The number of milliseconds connectors will wait for another HTTP request before closing the connection.
|
||||
* The default value is to use the value that has been set for the connectionTimeout attribute.
|
||||
* Use a value of -1 to indicate no (i.e. infinite) timeout.
|
||||
* Time in milliseconds that connectors will wait for another HTTP request before
|
||||
* closing the connection. When not set, the connector's container-specific default
|
||||
* will be used. Use a value of -1 to indicate no (i.e. infinite) timeout.
|
||||
*/
|
||||
private int connectionTimeout = -1;
|
||||
private Integer connectionTimeout;
|
||||
|
||||
private Session session = new Session();
|
||||
|
||||
@@ -375,11 +374,11 @@ public class ServerProperties
|
||||
return (platform == null ? false : platform.isUsingForwardHeaders());
|
||||
}
|
||||
|
||||
public int getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
public Integer getConnectionTimeout() {
|
||||
return this.connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(final int connectionTimeout) {
|
||||
public void setConnectionTimeout(Integer connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
@@ -786,14 +785,19 @@ public class ServerProperties
|
||||
if (getUriEncoding() != null) {
|
||||
factory.setUriEncoding(getUriEncoding());
|
||||
}
|
||||
customizeConnectionTimeout(serverProperties, factory);
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory,
|
||||
serverProperties.getConnectionTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeConnectionTimeout(final ServerProperties serverProperties, final TomcatEmbeddedServletContainerFactory factory) {
|
||||
private void customizeConnectionTimeout(
|
||||
TomcatEmbeddedServletContainerFactory factory, int connectionTimeout) {
|
||||
for (Connector connector : factory.getAdditionalTomcatConnectors()) {
|
||||
if (connector.getProtocolHandler() instanceof AbstractProtocol) {
|
||||
final AbstractProtocol handler = (AbstractProtocol) connector.getProtocolHandler();
|
||||
handler.setConnectionTimeout(serverProperties.getConnectionTimeout());
|
||||
AbstractProtocol<?> handler = (AbstractProtocol<?>) connector
|
||||
.getProtocolHandler();
|
||||
handler.setConnectionTimeout(connectionTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1006,7 +1010,7 @@ public class ServerProperties
|
||||
}
|
||||
|
||||
void customizeJetty(final ServerProperties serverProperties,
|
||||
JettyEmbeddedServletContainerFactory factory) {
|
||||
JettyEmbeddedServletContainerFactory factory) {
|
||||
factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders());
|
||||
if (this.acceptors != null) {
|
||||
factory.setAcceptors(this.acceptors);
|
||||
@@ -1022,17 +1026,23 @@ public class ServerProperties
|
||||
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
|
||||
}
|
||||
|
||||
customizeConnectionTimeout(serverProperties, factory);
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory,
|
||||
serverProperties.getConnectionTimeout());
|
||||
}
|
||||
}
|
||||
private void customizeConnectionTimeout(final ServerProperties serverProperties,
|
||||
final JettyEmbeddedServletContainerFactory factory) {
|
||||
|
||||
private void customizeConnectionTimeout(
|
||||
JettyEmbeddedServletContainerFactory factory,
|
||||
final int connectionTimeout) {
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
@Override
|
||||
public void customize(final Server server) {
|
||||
for (org.eclipse.jetty.server.Connector connector : server.getConnectors()) {
|
||||
if (connector instanceof ServerConnector) {
|
||||
ServerConnector serverConnector = (ServerConnector) connector;
|
||||
serverConnector.setIdleTimeout(serverProperties.getConnectionTimeout());
|
||||
public void customize(Server server) {
|
||||
for (org.eclipse.jetty.server.Connector connector : server
|
||||
.getConnectors()) {
|
||||
if (connector instanceof AbstractConnector) {
|
||||
((AbstractConnector) connector)
|
||||
.setIdleTimeout(connectionTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1193,7 +1203,7 @@ public class ServerProperties
|
||||
}
|
||||
|
||||
void customizeUndertow(final ServerProperties serverProperties,
|
||||
UndertowEmbeddedServletContainerFactory factory) {
|
||||
UndertowEmbeddedServletContainerFactory factory) {
|
||||
if (this.bufferSize != null) {
|
||||
factory.setBufferSize(this.bufferSize);
|
||||
}
|
||||
@@ -1227,14 +1237,20 @@ public class ServerProperties
|
||||
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
|
||||
}
|
||||
|
||||
customizeConnectionTimeout(serverProperties, factory);
|
||||
if (serverProperties.getConnectionTimeout() != null) {
|
||||
customizeConnectionTimeout(factory,
|
||||
serverProperties.getConnectionTimeout());
|
||||
}
|
||||
}
|
||||
private void customizeConnectionTimeout(final ServerProperties serverProperties,
|
||||
final UndertowEmbeddedServletContainerFactory factory) {
|
||||
|
||||
private void customizeConnectionTimeout(
|
||||
UndertowEmbeddedServletContainerFactory factory,
|
||||
final int connectionTimeout) {
|
||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||
@Override
|
||||
public void customize(Builder builder) {
|
||||
builder.setSocketOption(UndertowOptions.NO_REQUEST_TIMEOUT, serverProperties.getConnectionTimeout());
|
||||
builder.setSocketOption(UndertowOptions.NO_REQUEST_TIMEOUT,
|
||||
connectionTimeout);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -149,6 +149,7 @@ content into your application; rather pick only the properties that you need.
|
||||
server.compression.excluded-user-agents= # List of user-agents to exclude from compression.
|
||||
server.compression.mime-types= # Comma-separated list of MIME types that should be compressed. For instance `text/html,text/css,application/json`
|
||||
server.compression.min-response-size= # Minimum response size that is required for compression to be performed. For instance 2048
|
||||
server.connection-timeout= # Time in milliseconds that connectors will wait for another HTTP request before closing the connection. When not set, the connector's container-specific default will be used. Use a value of -1 to indicate no (i.e. infinite) timeout.
|
||||
server.context-parameters.*= # Servlet context init parameters. For instance `server.context-parameters.a=alpha`
|
||||
server.context-path= # Context path of the application.
|
||||
server.display-name=application # Display name of the application.
|
||||
|
||||
Reference in New Issue
Block a user