This approach can lead to false positives (it does not take into account q values โโor content types, which application / json is a substring).
You can find a decent Accept header parser in this XHTML article . You will have to transfer the algorithm to your chosen language and adapt it for the types of content that you use.
source
share