Skip to content

Commit 64a8326

Browse files
qxobclozel
authored andcommitted
Set UTF-8 charset for whitelabel HTML error pages
This commit changes the HTTP response Content-Type for whitelabel error pages with Spring WebFlux. See gh-16611
1 parent 593bc22 commit 64a8326

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ protected RouterFunction<ServerResponse> getRoutingFunction(
105105
this::renderErrorResponse);
106106
}
107107

108+
private static final MediaType HTML_CONTENT_TYPE = MediaType.valueOf(MediaType.TEXT_HTML_VALUE+";charset=UTF-8");
109+
108110
/**
109111
* Render the error information as an HTML view.
110112
* @param request the current request
@@ -115,7 +117,7 @@ protected Mono<ServerResponse> renderErrorView(ServerRequest request) {
115117
Map<String, Object> error = getErrorAttributes(request, includeStackTrace);
116118
HttpStatus errorStatus = getHttpStatus(error);
117119
ServerResponse.BodyBuilder responseBody = ServerResponse.status(errorStatus)
118-
.contentType(MediaType.TEXT_HTML);
120+
.contentType(HTML_CONTENT_TYPE);
119121
return Flux
120122
.just("error/" + errorStatus.value(),
121123
"error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error")

0 commit comments

Comments
 (0)