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
fe3de281
Commit
fe3de281
authored
Jun 06, 2018
by
Brian Clozel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.0.x'
parents
ab19db19
7cbbd95f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
DefaultErrorWebExceptionHandler.java
...e/web/reactive/error/DefaultErrorWebExceptionHandler.java
+11
-5
DefaultErrorWebExceptionHandlerIntegrationTests.java
...rror/DefaultErrorWebExceptionHandlerIntegrationTests.java
+10
-0
No files found.
spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java
View file @
fe3de281
...
...
@@ -32,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ResourceProperties;
import
org.springframework.boot.web.reactive.error.ErrorAttributes
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.InvalidMediaTypeException
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.reactive.function.BodyInserters
;
import
org.springframework.web.reactive.function.server.RequestPredicate
;
...
...
@@ -184,11 +185,16 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
*/
protected
RequestPredicate
acceptsTextHtml
()
{
return
(
serverRequest
)
->
{
List
<
MediaType
>
acceptedMediaTypes
=
serverRequest
.
headers
().
accept
();
acceptedMediaTypes
.
remove
(
MediaType
.
ALL
);
MediaType
.
sortBySpecificityAndQuality
(
acceptedMediaTypes
);
return
acceptedMediaTypes
.
stream
()
.
anyMatch
(
MediaType
.
TEXT_HTML
::
isCompatibleWith
);
try
{
List
<
MediaType
>
acceptedMediaTypes
=
serverRequest
.
headers
().
accept
();
acceptedMediaTypes
.
remove
(
MediaType
.
ALL
);
MediaType
.
sortBySpecificityAndQuality
(
acceptedMediaTypes
);
return
acceptedMediaTypes
.
stream
()
.
anyMatch
(
MediaType
.
TEXT_HTML
::
isCompatibleWith
);
}
catch
(
InvalidMediaTypeException
ex
)
{
return
false
;
}
};
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java
View file @
fe3de281
...
...
@@ -279,6 +279,16 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
});
}
@Test
public
void
invalidAcceptMediaType
()
{
this
.
contextRunner
.
run
((
context
)
->
{
WebTestClient
client
=
WebTestClient
.
bindToApplicationContext
(
context
)
.
build
();
client
.
get
().
uri
(
"/notfound"
).
header
(
"Accept"
,
"v=3.0"
).
exchange
()
.
expectStatus
().
isEqualTo
(
HttpStatus
.
NOT_FOUND
);
});
}
@Configuration
public
static
class
Application
{
...
...
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