I want to write a (ktor) server, with a custom content negotiation plugin, to provide 1 endpoint with two different input/output formats (mime types), namely xml (application/xml) and json (application/json), depending on the accept header.
If the caller request an unsupported mime type, the server responds with 406, Not applicable. That’s easy.
But I also want to use the problem rfc for error handling, that uses application/problem+xml and application/problem+json.
This is the problem: the mime type are different with different semantic, but roughly compatible based on the suffix (+xml/+json).
After reading the RFCs, I still unsure about the accept header/mime type handling because the RFCs don’t mention suffix handling (it was added later):
Should the server only validate the accept header for the expected successful response (and returns the error in the requested format based on the suffix mime type)?
Or should the accept header also be validated for the error response type?
In this case, should the accept header contain both mime types?