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
ea44ae6a
Commit
ea44ae6a
authored
Apr 10, 2016
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
parent
6d2f88ed
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
32 deletions
+108
-32
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+50
-27
SizeThreshold.java
...springframework/boot/autoconfigure/web/SizeThreshold.java
+52
-0
ServerPropertiesTests.java
...amework/boot/autoconfigure/web/ServerPropertiesTests.java
+3
-3
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+3
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
ea44ae6a
...
...
@@ -32,7 +32,6 @@ import javax.validation.constraints.NotNull;
import
io.undertow.Undertow.Builder
;
import
io.undertow.UndertowOptions
;
import
org.apache.catalina.Context
;
import
org.apache.catalina.connector.Connector
;
import
org.apache.catalina.valves.AccessLogValve
;
...
...
@@ -655,10 +654,11 @@ public class ServerProperties
/**
* Get 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
@DeprecatedConfigurationProperty
(
replacement
=
"server.max
HttpHeaderS
ize"
)
@DeprecatedConfigurationProperty
(
replacement
=
"server.max
-http-header-s
ize"
)
public
int
getMaxHttpHeaderSize
()
{
return
this
.
maxHttpHeaderSize
;
}
...
...
@@ -666,7 +666,8 @@ public class ServerProperties
/**
* Set 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
public
void
setMaxHttpHeaderSize
(
int
maxHttpHeaderSize
)
{
...
...
@@ -754,11 +755,10 @@ public class ServerProperties
if
(
this
.
minSpareThreads
>
0
)
{
customizeMinThreads
(
factory
);
}
if
(
serverProperties
.
getMaxHttpHeaderSize
()
>
0
)
{
customizeMaxHttpHeaderSize
(
factory
,
serverProperties
.
getMaxHttpHeaderSize
());
}
else
if
(
this
.
maxHttpHeaderSize
>
0
)
{
customizeMaxHttpHeaderSize
(
factory
,
this
.
maxHttpHeaderSize
);
int
maxHttpHeaderSize
=
(
serverProperties
.
getMaxHttpHeaderSize
()
>
0
?
serverProperties
.
getMaxHttpHeaderSize
()
:
this
.
maxHttpHeaderSize
);
if
(
maxHttpHeaderSize
>
0
)
{
customizeMaxHttpHeaderSize
(
factory
,
maxHttpHeaderSize
);
}
if
(
serverProperties
.
getMaxHttpPostSize
()
>
0
)
{
customizeMaxHttpPostSize
(
factory
,
serverProperties
.
getMaxHttpPostSize
());
...
...
@@ -841,7 +841,8 @@ public class ServerProperties
@SuppressWarnings
(
"rawtypes"
)
private
void
customizeMaxHttpHeaderSize
(
TomcatEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
TomcatEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
@Override
...
...
@@ -857,12 +858,15 @@ public class ServerProperties
}
private
void
customizeMaxHttpPostSize
(
TomcatEmbeddedServletContainerFactory
factory
,
final
int
maxHttpPostSize
)
{
TomcatEmbeddedServletContainerFactory
factory
,
final
int
maxHttpPostSize
)
{
factory
.
addConnectorCustomizers
(
new
TomcatConnectorCustomizer
()
{
@Override
public
void
customize
(
Connector
connector
)
{
connector
.
setMaxPostSize
(
maxHttpPostSize
);
}
});
}
...
...
@@ -952,7 +956,8 @@ public class ServerProperties
JettyEmbeddedServletContainerFactory
factory
)
{
factory
.
setUseForwardHeaders
(
serverProperties
.
getOrDeduceUseForwardHeaders
());
if
(
serverProperties
.
getMaxHttpHeaderSize
()
>
0
)
{
customizeMaxHttpHeaderSize
(
factory
,
serverProperties
.
getMaxHttpHeaderSize
());
customizeMaxHttpHeaderSize
(
factory
,
serverProperties
.
getMaxHttpHeaderSize
());
}
if
(
serverProperties
.
getMaxHttpPostSize
()
>
0
)
{
customizeMaxHttpPostSize
(
factory
,
serverProperties
.
getMaxHttpPostSize
());
...
...
@@ -960,23 +965,31 @@ public class ServerProperties
}
private
void
customizeMaxHttpHeaderSize
(
JettyEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
JettyEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
factory
.
addServerCustomizers
(
new
JettyServerCustomizer
()
{
@Override
public
void
customize
(
Server
server
)
{
org
.
eclipse
.
jetty
.
server
.
Connector
[]
connectors
=
server
.
getConnectors
();
for
(
org
.
eclipse
.
jetty
.
server
.
Connector
connector
:
connectors
)
{
for
(
ConnectionFactory
connectionFactory
:
connector
.
getConnectionFactories
())
{
for
(
org
.
eclipse
.
jetty
.
server
.
Connector
connector
:
server
.
getConnectors
())
{
for
(
ConnectionFactory
connectionFactory
:
connector
.
getConnectionFactories
())
{
if
(
connectionFactory
instanceof
HttpConfiguration
.
ConnectionFactory
)
{
HttpConfiguration
httpConfig
=
((
HttpConfiguration
.
ConnectionFactory
)
connectionFactory
)
.
getHttpConfiguration
();
httpConfig
.
setRequestHeaderSize
(
maxHttpHeaderSize
);
httpConfig
.
setResponseHeaderSize
(
maxHttpHeaderSize
);
customize
(
(
HttpConfiguration
.
ConnectionFactory
)
connectionFactory
);
}
}
}
}
private
void
customize
(
HttpConfiguration
.
ConnectionFactory
factory
)
{
HttpConfiguration
configuration
=
factory
.
getHttpConfiguration
();
configuration
.
setRequestHeaderSize
(
maxHttpHeaderSize
);
configuration
.
setResponseHeaderSize
(
maxHttpHeaderSize
);
}
});
}
...
...
@@ -993,7 +1006,8 @@ public class ServerProperties
Handler
...
handlers
)
{
for
(
Handler
handler
:
handlers
)
{
if
(
handler
instanceof
ContextHandler
)
{
((
ContextHandler
)
handler
).
setMaxFormContentSize
(
maxHttpPostSize
);
((
ContextHandler
)
handler
)
.
setMaxFormContentSize
(
maxHttpPostSize
);
}
else
if
(
handler
instanceof
HandlerWrapper
)
{
setHandlerMaxHttpPostSize
(
maxHttpPostSize
,
...
...
@@ -1112,7 +1126,8 @@ public class ServerProperties
}
factory
.
setUseForwardHeaders
(
serverProperties
.
getOrDeduceUseForwardHeaders
());
if
(
serverProperties
.
getMaxHttpHeaderSize
()
>
0
)
{
customizeMaxHttpHeaderSize
(
factory
,
serverProperties
.
getMaxHttpHeaderSize
());
customizeMaxHttpHeaderSize
(
factory
,
serverProperties
.
getMaxHttpHeaderSize
());
}
if
(
serverProperties
.
getMaxHttpPostSize
()
>
0
)
{
customizeMaxHttpPostSize
(
factory
,
serverProperties
.
getMaxHttpPostSize
());
...
...
@@ -1120,22 +1135,30 @@ public class ServerProperties
}
private
void
customizeMaxHttpHeaderSize
(
UndertowEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
UndertowEmbeddedServletContainerFactory
factory
,
final
int
maxHttpHeaderSize
)
{
factory
.
addBuilderCustomizers
(
new
UndertowBuilderCustomizer
()
{
@Override
public
void
customize
(
Builder
builder
)
{
builder
.
setServerOption
(
UndertowOptions
.
MAX_HEADER_SIZE
,
maxHttpHeaderSize
);
builder
.
setServerOption
(
UndertowOptions
.
MAX_HEADER_SIZE
,
maxHttpHeaderSize
);
}
});
}
private
void
customizeMaxHttpPostSize
(
UndertowEmbeddedServletContainerFactory
factory
,
final
int
maxHttpPostSize
)
{
UndertowEmbeddedServletContainerFactory
factory
,
final
int
maxHttpPostSize
)
{
factory
.
addBuilderCustomizers
(
new
UndertowBuilderCustomizer
()
{
@Override
public
void
customize
(
Builder
builder
)
{
builder
.
setServerOption
(
UndertowOptions
.
MAX_ENTITY_SIZE
,
(
long
)
maxHttpPostSize
);
builder
.
setServerOption
(
UndertowOptions
.
MAX_ENTITY_SIZE
,
(
long
)
maxHttpPostSize
);
}
});
}
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/SizeThreshold.java
0 → 100644
View file @
ea44ae6a
/*
* 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
));
}
}
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java
View file @
ea44ae6a
...
...
@@ -253,11 +253,11 @@ public class ServerPropertiesTests {
}
@Test
public
void
testCustomize
Tomcat
HeaderSize
()
throws
Exception
{
public
void
testCustomizeHeaderSize
()
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<
String
,
String
>();
map
.
put
(
"server.
tomcat.
maxHttpHeaderSize"
,
"9999"
);
map
.
put
(
"server.maxHttpHeaderSize"
,
"9999"
);
bindProperties
(
map
);
assertThat
(
this
.
properties
.
get
Tomcat
().
get
MaxHttpHeaderSize
()).
isEqualTo
(
9999
);
assertThat
(
this
.
properties
.
getMaxHttpHeaderSize
()).
isEqualTo
(
9999
);
}
@Test
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
ea44ae6a
...
...
@@ -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-path= # Context path 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.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.
...
...
@@ -168,6 +170,7 @@ content into your application; rather pick only the properties that you need.
server.port=8080 # Server HTTP port.
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.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.domain= # Domain 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.
172\\.1[6-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.
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.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.
...
...
@@ -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.io-threads= # Number of I/O threads to create for the worker.
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])
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
...
...
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