Content Type being append with charset=ISO-8859-1
See original GitHub issueHello!
I’m updating a Spring Boot 2.2 app with Spring Cloud Hoxton.SR1 to Spring Boot 2.3 with Hoxton.SR5, and the provider tests started to fail. The test fail with the following message:
DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=ISO-8859-1' not supported]
Something is appending the charset=ISO-8859-1
to the Content-Type
header, even tho our contract DSL sets it to application/json
only:
Contract.make {
description 'create something'
request {
method POST()
url '/something'
body(
property: 'value'
)
headers {
contentType(applicationJson()) // This is "application/json"
}
}
response {
status OK()
}
}
I think UTF-8 is the default for Spring Boot 2.2 onward, so it was not necessary anymore to use applicationJsonUtf8()
as content type. If I do change the content type to applicationJsonUtf8()
, then that charset=ISO-8859-1
is not appended and the test pass.
Is appending a default charset an expected behavior for Spring Cloud Contract?
Best regards, Rafael Pacheco.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:16 (5 by maintainers)
Top Results From Across the Web
Content-type header in response is getting appended by ...
Internally, it would append charset=ISO-8859-1 to the content-type header if not specified. As I wanted to remove this, changed method ...
Read more >Why does the browser add or replace the Content-type ...
Then append ` ;charset=UTF-8 ` to Content-Type. String: ... UTF-8 & ISO-8859-1 are identical to ASCII for the values from 0 to 127....
Read more >Character Encoding Issues - Apache Software Foundation
I'm having a problem with character encoding in Tomcat 5 ... An example of such a header is Content-Type: text/html; charset=ISO-8859-1 which explicitly ......
Read more >HTTP authentication does not support non-ISO-8859-1 ...
(maybe any charset given in the Content-Type header of the response ... If (a), we should at least stop non-ISO-8859-1 characters from being...
Read more >Character sets/Encoding - IBM
The default character encoding when reading is iso-8859–1. ... overridden in turn by a header of the type " Content-type: text/plain; charset=iso-8859–1 "....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi all, I had a simial issue, here my investigations: Spring Boot 2.3 uses Spring-web 5.2.7, (Spring Boot 2.2 used Spring-Web 5.2.6) Spring-web v.5.2.7 has a class AbstractJackson2HttpMessageConverter and it was modified - it started to check encoding for Json body (canRead(@Nullable MediaType mediaType)), so now only null encodign or UTF-xx supported.
On other hand RestAssured (3.3 in my case) by default uses ISO_8859_1 as defaultContentCharset (see deafult constructor of RestAssuredMockMvcConfig -> new EncoderConfig()) and if you don’t specify any charset excplisitly in the request content-type - it will add the defalt one.
So Spring Boot 2.3 (Spring Web 5.2.7) becomes more strict to headers.
My solution was to bring custom configuration to RestAssured:
RestAssuredMockMvc.config = new RestAssuredMockMvcConfig() .encoderConfig(new EncoderConfig(UTF_8.name(), UTF_8.name()));
or opt-out appending of default content charset:
EncoderConfig encoderConfig = new EncoderConfig() .appendDefaultContentCharsetToContentTypeIfUndefined(false); RestAssuredMockMvcConfig restAssuredConf = new RestAssuredMockMvcConfig() .encoderConfig(encoderConfig); RestAssuredMockMvc.config = restAssuredConf;
Indeed until Boot bumps Rest Assured to 4.x I guess we need to do