Carlos Alberto
Carlos Alberto

Reputation: 8585

Property for CharacterEncodingFilter in SpringBoot

I wonder if can replace the filter CharacterEncodingFilter by the HttpEncodingProperties.

I saw at documentation below ones:

# HTTP encoding (HttpEncodingProperties)
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true

Will it have the same effect that applying the filter manually? Another question, if I want to inform Spring Boot to keep the filter (properties) as async. Via filter I can inform it, setAsyncSupported(true).

Tks,

Upvotes: 1

Views: 2938

Answers (1)

Carlos Alberto
Carlos Alberto

Reputation: 8585

Spring Boot has many auto configurations per default, and http encoding is just one more using this concept.

Looking into the source code of HttpEncodingAutoConfiguration class, the filter CharacterEncodingFilter is created to encode all requests made to server. If you don't specify any property in application.properties the filter will be created using UTF-8, however if you decide creating this filter manually Spring Boot will use yours.

See source code: https://github.com/spring-projects/spring-boot/blob/2.6.x/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.java

Upvotes: 1

Related Questions