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
d5236b91
Commit
d5236b91
authored
Oct 15, 2018
by
Brian Clozel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
9e5f1715
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
41 deletions
+39
-41
WebFluxAutoConfiguration.java
.../autoconfigure/web/reactive/WebFluxAutoConfiguration.java
+12
-11
WebFluxAutoConfigurationTests.java
...configure/web/reactive/WebFluxAutoConfigurationTests.java
+27
-30
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java
View file @
d5236b91
...
...
@@ -148,17 +148,11 @@ public class WebFluxAutoConfiguration {
logger
.
debug
(
"Default resource handling disabled"
);
return
;
}
Duration
cachePeriod
=
this
.
resourceProperties
.
getCache
().
getPeriod
();
ResourceProperties
.
Cache
.
Cachecontrol
cacheControl
=
this
.
resourceProperties
.
getCache
().
getCachecontrol
();
if
(!
registry
.
hasMappingForPattern
(
"/webjars/**"
))
{
ResourceHandlerRegistration
registration
=
registry
.
addResourceHandler
(
"/webjars/**"
)
.
addResourceLocations
(
"classpath:/META-INF/resources/webjars/"
);
if
(
cachePeriod
!=
null
&&
cacheControl
.
getMaxAge
()
==
null
)
{
cacheControl
.
setMaxAge
(
cachePeriod
);
}
registration
.
setCacheControl
(
cacheControl
.
toHttpCacheControl
());
configureResourceCaching
(
registration
);
customizeResourceHandlerRegistration
(
registration
);
}
String
staticPathPattern
=
this
.
webFluxProperties
.
getStaticPathPattern
();
...
...
@@ -166,14 +160,21 @@ public class WebFluxAutoConfiguration {
ResourceHandlerRegistration
registration
=
registry
.
addResourceHandler
(
staticPathPattern
).
addResourceLocations
(
this
.
resourceProperties
.
getStaticLocations
());
if
(
cachePeriod
!=
null
&&
cacheControl
.
getMaxAge
()
==
null
)
{
cacheControl
.
setMaxAge
(
cachePeriod
);
}
registration
.
setCacheControl
(
cacheControl
.
toHttpCacheControl
());
configureResourceCaching
(
registration
);
customizeResourceHandlerRegistration
(
registration
);
}
}
private
void
configureResourceCaching
(
ResourceHandlerRegistration
registration
)
{
Duration
cachePeriod
=
this
.
resourceProperties
.
getCache
().
getPeriod
();
ResourceProperties
.
Cache
.
Cachecontrol
cacheControl
=
this
.
resourceProperties
.
getCache
().
getCachecontrol
();
if
(
cachePeriod
!=
null
&&
cacheControl
.
getMaxAge
()
==
null
)
{
cacheControl
.
setMaxAge
(
cachePeriod
);
}
registration
.
setCacheControl
(
cacheControl
.
toHttpCacheControl
());
}
@Override
public
void
configureViewResolvers
(
ViewResolverRegistry
registry
)
{
this
.
viewResolvers
.
orderedStream
().
forEach
(
registry:
:
viewResolver
);
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java
View file @
d5236b91
...
...
@@ -31,10 +31,10 @@ import org.springframework.beans.DirectFieldAccessor;
import
org.springframework.boot.autoconfigure.AutoConfigurations
;
import
org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration
;
import
org.springframework.boot.autoconfigure.validation.ValidatorAdapter
;
import
org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext
;
import
org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner
;
import
org.springframework.boot.web.codec.CodecCustomizer
;
import
org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -415,7 +415,17 @@ public class WebFluxAutoConfigurationTests {
@Test
public
void
cachePeriod
()
{
this
.
contextRunner
.
withPropertyValues
(
"spring.resources.cache.period:5"
)
.
run
(
this
::
assertCachePeriod
);
.
run
((
context
)
->
{
Map
<
PathPattern
,
Object
>
handlerMap
=
getHandlerMap
(
context
);
assertThat
(
handlerMap
).
hasSize
(
2
);
for
(
Object
handler
:
handlerMap
.
values
())
{
if
(
handler
instanceof
ResourceWebHandler
)
{
assertThat
(((
ResourceWebHandler
)
handler
).
getCacheControl
())
.
isEqualToComparingFieldByField
(
CacheControl
.
maxAge
(
5
,
TimeUnit
.
SECONDS
));
}
}
});
}
@Test
...
...
@@ -423,42 +433,29 @@ public class WebFluxAutoConfigurationTests {
this
.
contextRunner
.
withPropertyValues
(
"spring.resources.cache.cachecontrol.max-age:5"
,
"spring.resources.cache.cachecontrol.proxy-revalidate:true"
)
.
run
(
this
::
assertCacheControl
);
}
private
void
assertCachePeriod
(
AssertableReactiveWebApplicationContext
context
)
{
Map
<
PathPattern
,
Object
>
handlerMap
=
getHandlerMap
(
context
.
getBean
(
"resourceHandlerMapping"
,
HandlerMapping
.
class
));
assertThat
(
handlerMap
).
hasSize
(
2
);
for
(
Object
handler
:
handlerMap
.
values
())
{
if
(
handler
instanceof
ResourceWebHandler
)
{
assertThat
(((
ResourceWebHandler
)
handler
).
getCacheControl
())
.
isEqualToComparingFieldByField
(
CacheControl
.
maxAge
(
5
,
TimeUnit
.
SECONDS
));
}
}
.
run
((
context
)
->
{
Map
<
PathPattern
,
Object
>
handlerMap
=
getHandlerMap
(
context
);
assertThat
(
handlerMap
).
hasSize
(
2
);
for
(
Object
handler
:
handlerMap
.
values
())
{
if
(
handler
instanceof
ResourceWebHandler
)
{
assertThat
(((
ResourceWebHandler
)
handler
).
getCacheControl
())
.
isEqualToComparingFieldByField
(
CacheControl
.
maxAge
(
5
,
TimeUnit
.
SECONDS
)
.
proxyRevalidate
());
}
}
});
}
private
Map
<
PathPattern
,
Object
>
getHandlerMap
(
HandlerMapping
mapping
)
{
private
Map
<
PathPattern
,
Object
>
getHandlerMap
(
ApplicationContext
context
)
{
HandlerMapping
mapping
=
context
.
getBean
(
"resourceHandlerMapping"
,
HandlerMapping
.
class
);
if
(
mapping
instanceof
SimpleUrlHandlerMapping
)
{
return
((
SimpleUrlHandlerMapping
)
mapping
).
getHandlerMap
();
}
return
Collections
.
emptyMap
();
}
private
void
assertCacheControl
(
AssertableReactiveWebApplicationContext
context
)
{
Map
<
PathPattern
,
Object
>
handlerMap
=
getHandlerMap
(
context
.
getBean
(
"resourceHandlerMapping"
,
HandlerMapping
.
class
));
assertThat
(
handlerMap
).
hasSize
(
2
);
for
(
Object
handler
:
handlerMap
.
values
())
{
if
(
handler
instanceof
ResourceWebHandler
)
{
assertThat
(((
ResourceWebHandler
)
handler
).
getCacheControl
())
.
isEqualToComparingFieldByField
(
CacheControl
.
maxAge
(
5
,
TimeUnit
.
SECONDS
).
proxyRevalidate
());
}
}
}
@Configuration
protected
static
class
CustomArgumentResolvers
{
...
...
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