mimesniffer icon indicating copy to clipboard operation
mimesniffer copied to clipboard

JSON is not recognised

Open rickb777 opened this issue 2 years ago • 1 comments

application/json is widely used in REST APIs, but isn't detected by mimesniffer, nor by the default net/http sniffer.

This would be a useful addition for many people.

Correct sniffing should determine whether the content is valid JSON. If it isn't then the result would be "text/plain". This can be done using encoding/json via the json.Valid function.

rickb777 avatar Mar 17 '22 14:03 rickb777

Workaround:

mimesniffer.Register("application/json", func(bs []byte) bool {
    return json.Valid(bs)
})

rickb777 avatar Mar 17 '22 15:03 rickb777