There have been instances where the content-type
header of a request (such as one made by Firefox) includes not just information about the MIME type, but also details on encoding.
For example, when sending JSON via AJAX, instead of
application/json
(which was anticipated), Firefox sent:
application/json; charset=UTF-8
This behavior raises several questions:
- What are other possible "parameters" (or "options", or whatever term is used for the
charset
value) that could be included? - Will
application/json
consistently be listed first, or might the values be in a different order (e.g., could it becharset=UTF-8; application/json
)? - Is the separator always a
;
? - What is the standard method to test for a specific MIME type? Simply comparing headers is insufficient. Any suggestions or improvements beyond
?contentType === 'application/json || contentType.startsWith('application/json;')
PS: Regarding question #4, I've posted a separate inquiry. Please see Get an entire string or a substring, depending on a specific character