Search in sources :

Example 1 with CharacterEncodingFilter

use of org.springframework.web.filter.CharacterEncodingFilter in project spring-boot by spring-projects.

the class HttpEncodingAutoConfigurationTests method forceRequestOverridesForce.

@Test
public void forceRequestOverridesForce() throws Exception {
    load(EmptyConfiguration.class, "spring.http.encoding.force:true", "spring.http.encoding.force-request:false");
    CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
    assertCharacterEncodingFilter(filter, "UTF-8", false, true);
}
Also used : CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) Test(org.junit.Test)

Example 2 with CharacterEncodingFilter

use of org.springframework.web.filter.CharacterEncodingFilter in project cas by apereo.

the class CasFiltersConfiguration method characterEncodingFilter.

@RefreshScope
@Bean
public FilterRegistrationBean characterEncodingFilter() {
    final FilterRegistrationBean bean = new FilterRegistrationBean();
    bean.setFilter(new CharacterEncodingFilter(casProperties.getHttpWebRequest().getWeb().getEncoding(), casProperties.getHttpWebRequest().getWeb().isForceEncoding()));
    bean.setUrlPatterns(Collections.singleton("/*"));
    bean.setName("characterEncodingFilter");
    bean.setAsyncSupported(true);
    return bean;
}
Also used : CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with CharacterEncodingFilter

use of org.springframework.web.filter.CharacterEncodingFilter in project zipkin by openzipkin.

the class ZipkinUiAutoConfiguration method characterEncodingFilter.

/**
   * 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".
   *
   * See https://github.com/spring-projects/spring-boot/issues/5459
   */
@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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) Order(org.springframework.core.annotation.Order) Bean(org.springframework.context.annotation.Bean)

Example 4 with CharacterEncodingFilter

use of org.springframework.web.filter.CharacterEncodingFilter in project spring-boot by spring-projects.

the class HttpEncodingAutoConfiguration method characterEncodingFilter.

@Bean
@ConditionalOnMissingBean(CharacterEncodingFilter.class)
public CharacterEncodingFilter characterEncodingFilter() {
    CharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
    filter.setEncoding(this.properties.getCharset().name());
    filter.setForceRequestEncoding(this.properties.shouldForce(Type.REQUEST));
    filter.setForceResponseEncoding(this.properties.shouldForce(Type.RESPONSE));
    return filter;
}
Also used : OrderedCharacterEncodingFilter(org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter) CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) OrderedCharacterEncodingFilter(org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with CharacterEncodingFilter

use of org.springframework.web.filter.CharacterEncodingFilter in project spring-boot by spring-projects.

the class HttpEncodingAutoConfigurationTests method customFilterConfiguration.

@Test
public void customFilterConfiguration() {
    load(FilterConfiguration.class, "spring.http.encoding.charset:ISO-8859-15", "spring.http.encoding.force:false");
    CharacterEncodingFilter filter = this.context.getBean(CharacterEncodingFilter.class);
    assertCharacterEncodingFilter(filter, "US-ASCII", false, false);
}
Also used : CharacterEncodingFilter(org.springframework.web.filter.CharacterEncodingFilter) Test(org.junit.Test)

Aggregations

CharacterEncodingFilter (org.springframework.web.filter.CharacterEncodingFilter)11 Test (org.junit.Test)7 Bean (org.springframework.context.annotation.Bean)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Before (org.junit.Before)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)1 OrderedCharacterEncodingFilter (org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Order (org.springframework.core.annotation.Order)1 ShallowEtagHeaderFilter (org.springframework.web.filter.ShallowEtagHeaderFilter)1