Set utf-8 as default encoding
Describe the issue This is a follow up of https://github.com/mock-server/mockserver/issues/797 . It seems like https://github.com/mock-server/mockserver/commit/7408afbb03523736cf050a8d98d81589fcc4415b do following:
application/json; charset=utf-8is set: works as expected, utf8 encoding is used- no
Content-Typeheader is set: works as expected, utf8 encoding is used application/jsonis set: utf8 isn't used. ISO-8859-1 is still used
From my point of view, the last one should use utf8.
What you are trying to do
Mock a request with utf8 encoding and Content-Type: application/json header. Mock Server stores it in wrong encoding.
MockServer version 5.11.2
To Reproduce Steps to reproduce the issue:
- Send an utf8 encoded request with
Content-Type: application/jsonheader - Get all recorded requests from mock server
Expected behaviour
utf8 should be assumed even without explicit ; charset=utf-8 part the Content-Type header
MockServer Log
I'm facing the same problem: the unittests on my project were continuously failing because of this.
:+1: Don't see any reason for not using utf-8 as default encoding with application/json in Content-Type header set.
This problem is especially painful when using mock-server with spring. The common restTemplate media type is APPLICATION_JSON, so you have to change it to deprecated APPLICATION_JSON_UTF8. But it causes new problems: header in Spring is 'application/json;charset=UTF-8" while in the mock server - 'application/json; charset=utf-8" so you are not able to validate it using request().withContentType(...) expectation.
Still have this issue in dockerized mock-server also.
I'm pretty sure this is the correct standard for HTTP according to the exact specification but I can double check and potentially change it to the way you suggested as it's more practical.
Please take a look
https://datatracker.ietf.org/doc/html/rfc8259#section-11
Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.
https://datatracker.ietf.org/doc/html/rfc8259#section-8.1
JSON text exchanged between systems that are not part of a closed ecosystem MUST be encoded using UTF-8
https://www.rfc-editor.org/errata/eid5853 (Notes section)