|
|
|
@ -50,6 +50,7 @@ import org.springframework.util.unit.DataSize; |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Phillip Webb |
|
|
|
* @author Phillip Webb |
|
|
|
* @author HaiTao Zhang |
|
|
|
* @author HaiTao Zhang |
|
|
|
|
|
|
|
* @author Rafiullah Hamedy |
|
|
|
* @since 2.0.0 |
|
|
|
* @since 2.0.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JettyWebServerFactoryCustomizer |
|
|
|
public class JettyWebServerFactoryCustomizer |
|
|
|
@ -80,8 +81,8 @@ public class JettyWebServerFactoryCustomizer |
|
|
|
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes) |
|
|
|
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes) |
|
|
|
.when(this::isPositive).to((maxHttpHeaderSize) -> factory |
|
|
|
.when(this::isPositive).to((maxHttpHeaderSize) -> factory |
|
|
|
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize))); |
|
|
|
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize))); |
|
|
|
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive) |
|
|
|
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive) |
|
|
|
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize)); |
|
|
|
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize)); |
|
|
|
propertyMapper.from(jettyProperties::getMaxThreads).when(this::isPositive) |
|
|
|
propertyMapper.from(jettyProperties::getMaxThreads).when(this::isPositive) |
|
|
|
.to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads))); |
|
|
|
.to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads))); |
|
|
|
propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive) |
|
|
|
propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive) |
|
|
|
@ -118,24 +119,24 @@ public class JettyWebServerFactoryCustomizer |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) { |
|
|
|
private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) { |
|
|
|
factory.addServerCustomizers(new JettyServerCustomizer() { |
|
|
|
factory.addServerCustomizers(new JettyServerCustomizer() { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void customize(Server server) { |
|
|
|
public void customize(Server server) { |
|
|
|
setHandlerMaxHttpPostSize(maxHttpPostSize, server.getHandlers()); |
|
|
|
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, server.getHandlers()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setHandlerMaxHttpPostSize(int maxHttpPostSize, Handler... handlers) { |
|
|
|
private void setHandlerMaxHttpFormPostSize(int maxHttpPostSize, 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(maxHttpFormPostSize); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (handler instanceof HandlerWrapper) { |
|
|
|
else if (handler instanceof HandlerWrapper) { |
|
|
|
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerWrapper) handler).getHandler()); |
|
|
|
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerWrapper) handler).getHandler()); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (handler instanceof HandlerCollection) { |
|
|
|
else if (handler instanceof HandlerCollection) { |
|
|
|
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerCollection) handler).getHandlers()); |
|
|
|
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerCollection) handler).getHandlers()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|