-
Notifications
You must be signed in to change notification settings - Fork 41.5k
Closed
Description
CharacterEncodingFilter
is auto-configured such that it appends a charset to all resources. The trouble is that this adds charset to resources such as png files. This causes confusion for people debugging their apps.
I've overridden it like below, but wondering if there's a smarter way to address this.
/**
* This opts out of adding charset to png resources.
*
* <p>By default, {@linkplain CharacterEncodingFilter} adds a charset qualifier to all resources,
* which helps, as javascript assets include extended character sets. However, the filter also
* adds charset to well-known binary ones like png. This creates confusing content types, such as
* "image/png;charset=UTF-8".
*/
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public CharacterEncodingFilter characterEncodingFilter() {
CharacterEncodingFilter filter = new CharacterEncodingFilter() {
@Override
protected boolean shouldNotFilter(HttpServletRequest request) {
return request.getServletPath().endsWith(".png");
}
};
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
return filter;
}
wimdeblauwe
Metadata
Metadata
Assignees
Labels
type: bugA general bugA general bug