Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
511a2a07
Commit
511a2a07
authored
Oct 22, 2019
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x'
Closes gh-18695
parents
83d4d94e
b61b7b07
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
23 deletions
+68
-23
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+30
-8
JettyWebServerFactoryCustomizer.java
...nfigure/web/embedded/JettyWebServerFactoryCustomizer.java
+9
-8
TomcatWebServerFactoryCustomizer.java
...figure/web/embedded/TomcatWebServerFactoryCustomizer.java
+6
-5
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+9
-2
TomcatWebServerFactoryCustomizerTests.java
...e/web/embedded/TomcatWebServerFactoryCustomizerTests.java
+14
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
511a2a07
...
@@ -359,9 +359,9 @@ public class ServerProperties {
...
@@ -359,9 +359,9 @@ public class ServerProperties {
private
int
minSpareThreads
=
10
;
private
int
minSpareThreads
=
10
;
/**
/**
* Maximum size of the
HTTP post conten
t.
* Maximum size of the
form content in any HTTP post reques
t.
*/
*/
private
DataSize
maxHttpPostSize
=
DataSize
.
ofMegabytes
(
2
);
private
DataSize
maxHttp
Form
PostSize
=
DataSize
.
ofMegabytes
(
2
);
/**
/**
* Maximum amount of request body to swallow.
* Maximum amount of request body to swallow.
...
@@ -456,12 +456,23 @@ public class ServerProperties {
...
@@ -456,12 +456,23 @@ public class ServerProperties {
this
.
minSpareThreads
=
minSpareThreads
;
this
.
minSpareThreads
=
minSpareThreads
;
}
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"server.tomcat.max-http-form-post-size"
)
public
DataSize
getMaxHttpPostSize
()
{
public
DataSize
getMaxHttpPostSize
()
{
return
this
.
maxHttpPostSize
;
return
this
.
maxHttp
Form
PostSize
;
}
}
@Deprecated
public
void
setMaxHttpPostSize
(
DataSize
maxHttpPostSize
)
{
public
void
setMaxHttpPostSize
(
DataSize
maxHttpPostSize
)
{
this
.
maxHttpPostSize
=
maxHttpPostSize
;
this
.
maxHttpFormPostSize
=
maxHttpPostSize
;
}
public
DataSize
getMaxHttpFormPostSize
()
{
return
this
.
maxHttpFormPostSize
;
}
public
void
setMaxHttpFormPostSize
(
DataSize
maxHttpFormPostSize
)
{
this
.
maxHttpFormPostSize
=
maxHttpFormPostSize
;
}
}
public
Accesslog
getAccesslog
()
{
public
Accesslog
getAccesslog
()
{
...
@@ -927,9 +938,9 @@ public class ServerProperties {
...
@@ -927,9 +938,9 @@ public class ServerProperties {
private
final
Accesslog
accesslog
=
new
Accesslog
();
private
final
Accesslog
accesslog
=
new
Accesslog
();
/**
/**
* Maximum size of the
HTTP post or put conten
t.
* Maximum size of the
form content in any HTTP post reques
t.
*/
*/
private
DataSize
maxHttpPostSize
=
DataSize
.
ofBytes
(
200000
);
private
DataSize
maxHttp
Form
PostSize
=
DataSize
.
ofBytes
(
200000
);
/**
/**
* Number of acceptor threads to use. When the value is -1, the default, the
* Number of acceptor threads to use. When the value is -1, the default, the
...
@@ -967,12 +978,23 @@ public class ServerProperties {
...
@@ -967,12 +978,23 @@ public class ServerProperties {
return
this
.
accesslog
;
return
this
.
accesslog
;
}
}
@Deprecated
@DeprecatedConfigurationProperty
(
replacement
=
"server.jetty.max-http-form-post-size"
)
public
DataSize
getMaxHttpPostSize
()
{
public
DataSize
getMaxHttpPostSize
()
{
return
this
.
maxHttpPostSize
;
return
this
.
maxHttp
Form
PostSize
;
}
}
@Deprecated
public
void
setMaxHttpPostSize
(
DataSize
maxHttpPostSize
)
{
public
void
setMaxHttpPostSize
(
DataSize
maxHttpPostSize
)
{
this
.
maxHttpPostSize
=
maxHttpPostSize
;
this
.
maxHttpFormPostSize
=
maxHttpPostSize
;
}
public
DataSize
getMaxHttpFormPostSize
()
{
return
this
.
maxHttpFormPostSize
;
}
public
void
setMaxHttpFormPostSize
(
DataSize
maxHttpFormPostSize
)
{
this
.
maxHttpFormPostSize
=
maxHttpFormPostSize
;
}
}
public
Integer
getAcceptors
()
{
public
Integer
getAcceptors
()
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java
View file @
511a2a07
...
@@ -50,6 +50,7 @@ import org.springframework.util.unit.DataSize;
...
@@ -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
...
@@ -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:
:
getMaxHttp
Form
PostSize
).
asInt
(
DataSize:
:
toBytes
).
when
(
this
::
isPositive
)
.
to
((
maxHttp
PostSize
)
->
customizeMaxHttpPostSize
(
factory
,
maxHttp
PostSize
));
.
to
((
maxHttp
FormPostSize
)
->
customizeMaxHttpFormPostSize
(
factory
,
maxHttpForm
PostSize
));
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
...
@@ -118,24 +119,24 @@ public class JettyWebServerFactoryCustomizer
});
});
}
}
private
void
customizeMaxHttp
PostSize
(
ConfigurableJettyWebServerFactory
factory
,
int
maxHttp
PostSize
)
{
private
void
customizeMaxHttp
FormPostSize
(
ConfigurableJettyWebServerFactory
factory
,
int
maxHttpForm
PostSize
)
{
factory
.
addServerCustomizers
(
new
JettyServerCustomizer
()
{
factory
.
addServerCustomizers
(
new
JettyServerCustomizer
()
{
@Override
@Override
public
void
customize
(
Server
server
)
{
public
void
customize
(
Server
server
)
{
setHandlerMaxHttp
PostSize
(
maxHttp
PostSize
,
server
.
getHandlers
());
setHandlerMaxHttp
FormPostSize
(
maxHttpForm
PostSize
,
server
.
getHandlers
());
}
}
private
void
setHandlerMaxHttpPostSize
(
int
maxHttpPostSize
,
Handler
...
handlers
)
{
private
void
setHandlerMaxHttp
Form
PostSize
(
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
(
maxHttp
Form
PostSize
);
}
}
else
if
(
handler
instanceof
HandlerWrapper
)
{
else
if
(
handler
instanceof
HandlerWrapper
)
{
setHandlerMaxHttp
PostSize
(
maxHttp
PostSize
,
((
HandlerWrapper
)
handler
).
getHandler
());
setHandlerMaxHttp
FormPostSize
(
maxHttpForm
PostSize
,
((
HandlerWrapper
)
handler
).
getHandler
());
}
}
else
if
(
handler
instanceof
HandlerCollection
)
{
else
if
(
handler
instanceof
HandlerCollection
)
{
setHandlerMaxHttp
PostSize
(
maxHttp
PostSize
,
((
HandlerCollection
)
handler
).
getHandlers
());
setHandlerMaxHttp
FormPostSize
(
maxHttpForm
PostSize
,
((
HandlerCollection
)
handler
).
getHandlers
());
}
}
}
}
}
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java
View file @
511a2a07
...
@@ -54,6 +54,7 @@ import org.springframework.util.unit.DataSize;
...
@@ -54,6 +54,7 @@ import org.springframework.util.unit.DataSize;
* @author Chentao Qu
* @author Chentao Qu
* @author Andrew McGhie
* @author Andrew McGhie
* @author Dirk Deyne
* @author Dirk Deyne
* @author Rafiullah Hamedy
* @since 2.0.0
* @since 2.0.0
*/
*/
public
class
TomcatWebServerFactoryCustomizer
public
class
TomcatWebServerFactoryCustomizer
...
@@ -91,9 +92,9 @@ public class TomcatWebServerFactoryCustomizer
...
@@ -91,9 +92,9 @@ public class TomcatWebServerFactoryCustomizer
.
to
((
maxHttpHeaderSize
)
->
customizeMaxHttpHeaderSize
(
factory
,
maxHttpHeaderSize
));
.
to
((
maxHttpHeaderSize
)
->
customizeMaxHttpHeaderSize
(
factory
,
maxHttpHeaderSize
));
propertyMapper
.
from
(
tomcatProperties:
:
getMaxSwallowSize
).
whenNonNull
().
asInt
(
DataSize:
:
toBytes
)
propertyMapper
.
from
(
tomcatProperties:
:
getMaxSwallowSize
).
whenNonNull
().
asInt
(
DataSize:
:
toBytes
)
.
to
((
maxSwallowSize
)
->
customizeMaxSwallowSize
(
factory
,
maxSwallowSize
));
.
to
((
maxSwallowSize
)
->
customizeMaxSwallowSize
(
factory
,
maxSwallowSize
));
propertyMapper
.
from
(
tomcatProperties:
:
getMaxHttpPostSize
).
asInt
(
DataSize:
:
toBytes
)
propertyMapper
.
from
(
tomcatProperties:
:
getMaxHttp
Form
PostSize
).
asInt
(
DataSize:
:
toBytes
)
.
when
((
maxHttp
PostSize
)
->
maxHttp
PostSize
!=
0
)
.
when
((
maxHttp
FormPostSize
)
->
maxHttpForm
PostSize
!=
0
)
.
to
((
maxHttp
PostSize
)
->
customizeMaxHttpPostSize
(
factory
,
maxHttp
PostSize
));
.
to
((
maxHttp
FormPostSize
)
->
customizeMaxHttpFormPostSize
(
factory
,
maxHttpForm
PostSize
));
propertyMapper
.
from
(
tomcatProperties:
:
getAccesslog
).
when
(
ServerProperties
.
Tomcat
.
Accesslog
::
isEnabled
)
propertyMapper
.
from
(
tomcatProperties:
:
getAccesslog
).
when
(
ServerProperties
.
Tomcat
.
Accesslog
::
isEnabled
)
.
to
((
enabled
)
->
customizeAccessLog
(
factory
));
.
to
((
enabled
)
->
customizeAccessLog
(
factory
));
propertyMapper
.
from
(
tomcatProperties:
:
getUriEncoding
).
whenNonNull
().
to
(
factory:
:
setUriEncoding
);
propertyMapper
.
from
(
tomcatProperties:
:
getUriEncoding
).
whenNonNull
().
to
(
factory:
:
setUriEncoding
);
...
@@ -244,8 +245,8 @@ public class TomcatWebServerFactoryCustomizer
...
@@ -244,8 +245,8 @@ public class TomcatWebServerFactoryCustomizer
});
});
}
}
private
void
customizeMaxHttp
PostSize
(
ConfigurableTomcatWebServerFactory
factory
,
int
maxHttp
PostSize
)
{
private
void
customizeMaxHttp
FormPostSize
(
ConfigurableTomcatWebServerFactory
factory
,
int
maxHttpForm
PostSize
)
{
factory
.
addConnectorCustomizers
((
connector
)
->
connector
.
setMaxPostSize
(
maxHttpPostSize
));
factory
.
addConnectorCustomizers
((
connector
)
->
connector
.
setMaxPostSize
(
maxHttp
Form
PostSize
));
}
}
private
void
customizeAccessLog
(
ConfigurableTomcatWebServerFactory
factory
)
{
private
void
customizeAccessLog
(
ConfigurableTomcatWebServerFactory
factory
)
{
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
511a2a07
...
@@ -75,6 +75,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -75,6 +75,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Venil Noronha
* @author Venil Noronha
* @author Andrew McGhie
* @author Andrew McGhie
* @author HaiTao Zhang
* @author HaiTao Zhang
* @author Rafiullah Hamedy
*/
*/
class
ServerPropertiesTests
{
class
ServerPropertiesTests
{
...
@@ -310,6 +311,12 @@ class ServerPropertiesTests {
...
@@ -310,6 +311,12 @@ class ServerPropertiesTests {
.
isEqualTo
(
Duration
.
ofSeconds
((
new
StandardEngine
().
getBackgroundProcessorDelay
())));
.
isEqualTo
(
Duration
.
ofSeconds
((
new
StandardEngine
().
getBackgroundProcessorDelay
())));
}
}
@Test
void
tomcatMaxHttpFormPostSizeMatchesConnectorDefault
()
throws
Exception
{
assertThat
(
this
.
properties
.
getTomcat
().
getMaxHttpFormPostSize
().
toBytes
())
.
isEqualTo
(
getDefaultConnector
().
getMaxPostSize
());
}
@Test
@Test
void
tomcatUriEncodingMatchesConnectorDefault
()
throws
Exception
{
void
tomcatUriEncodingMatchesConnectorDefault
()
throws
Exception
{
assertThat
(
this
.
properties
.
getTomcat
().
getUriEncoding
().
name
())
assertThat
(
this
.
properties
.
getTomcat
().
getUriEncoding
().
name
())
...
@@ -341,7 +348,7 @@ class ServerPropertiesTests {
...
@@ -341,7 +348,7 @@ class ServerPropertiesTests {
}
}
@Test
@Test
void
jettyMaxHttpPostSizeMatchesDefault
()
throws
Exception
{
void
jettyMaxHttp
Form
PostSizeMatchesDefault
()
throws
Exception
{
JettyServletWebServerFactory
jettyFactory
=
new
JettyServletWebServerFactory
(
0
);
JettyServletWebServerFactory
jettyFactory
=
new
JettyServletWebServerFactory
(
0
);
JettyWebServer
jetty
=
(
JettyWebServer
)
jettyFactory
JettyWebServer
jetty
=
(
JettyWebServer
)
jettyFactory
.
getWebServer
((
ServletContextInitializer
)
(
servletContext
)
->
servletContext
.
getWebServer
((
ServletContextInitializer
)
(
servletContext
)
->
servletContext
...
@@ -393,7 +400,7 @@ class ServerPropertiesTests {
...
@@ -393,7 +400,7 @@ class ServerPropertiesTests {
assertThat
(
failure
.
get
()).
isNotNull
();
assertThat
(
failure
.
get
()).
isNotNull
();
String
message
=
failure
.
get
().
getCause
().
getMessage
();
String
message
=
failure
.
get
().
getCause
().
getMessage
();
int
defaultMaxPostSize
=
Integer
.
valueOf
(
message
.
substring
(
message
.
lastIndexOf
(
' '
)).
trim
());
int
defaultMaxPostSize
=
Integer
.
valueOf
(
message
.
substring
(
message
.
lastIndexOf
(
' '
)).
trim
());
assertThat
(
this
.
properties
.
getJetty
().
getMaxHttpPostSize
().
toBytes
()).
isEqualTo
(
defaultMaxPostSize
);
assertThat
(
this
.
properties
.
getJetty
().
getMaxHttp
Form
PostSize
().
toBytes
()).
isEqualTo
(
defaultMaxPostSize
);
}
}
finally
{
finally
{
jetty
.
stop
();
jetty
.
stop
();
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java
View file @
511a2a07
...
@@ -52,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -52,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artsiom Yudovin
* @author Artsiom Yudovin
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Andrew McGhie
* @author Andrew McGhie
* @author Rafiullah Hamedy
*/
*/
class
TomcatWebServerFactoryCustomizerTests
{
class
TomcatWebServerFactoryCustomizerTests
{
...
@@ -114,6 +115,12 @@ class TomcatWebServerFactoryCustomizerTests {
...
@@ -114,6 +115,12 @@ class TomcatWebServerFactoryCustomizerTests {
customizeAndRunServer
((
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(-
1
));
customizeAndRunServer
((
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(-
1
));
}
}
@Test
void
customDisableMaxHttpFormPostSize
()
{
bind
(
"server.tomcat.max-http-form-post-size=-1"
);
customizeAndRunServer
((
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(-
1
));
}
@Test
@Test
void
customMaxConnections
()
{
void
customMaxConnections
()
{
bind
(
"server.tomcat.max-connections=5"
);
bind
(
"server.tomcat.max-connections=5"
);
...
@@ -129,6 +136,13 @@ class TomcatWebServerFactoryCustomizerTests {
...
@@ -129,6 +136,13 @@ class TomcatWebServerFactoryCustomizerTests {
(
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(
10000
));
(
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(
10000
));
}
}
@Test
void
customMaxHttpFormPostSize
()
{
bind
(
"server.tomcat.max-http-form-post-size=10000"
);
customizeAndRunServer
(
(
server
)
->
assertThat
(
server
.
getTomcat
().
getConnector
().
getMaxPostSize
()).
isEqualTo
(
10000
));
}
@Test
@Test
void
customMaxHttpHeaderSize
()
{
void
customMaxHttpHeaderSize
()
{
bind
(
"server.max-http-header-size=1KB"
);
bind
(
"server.max-http-header-size=1KB"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment