Open abonie opened 5 years ago
While I can confirm this is a legit bug, it's been a long-time pet peeve of mine that application/json; charset=utf-8
is not a valid MIME type for the JSON protocol (see also https://stackoverflow.com/questions/4990095/json-specification-and-usage-of-bom-charset-encoding)
That is a fair point, but seems like this unfortunate application/json; charset=utf-8
is popular enough to justify supporting it anyway. For example I noticed this bug while trying to write a simple client using servant-client, and turns out that this is the Accept
header it creates by default if you want JSON...
Indeed we're hilariously inconsistent on this. e.g. we actually generate that content type!
@abonie if you want to patch it, I think this is all that needs to be toyed with (?): https://github.com/haskell/hackage-server/blob/b4638cd2879dc4300c696a0c96b5e9425a9f66bc/Distribution/Server/Framework/Resource.hs#L535
For example I noticed this bug while trying to write a simple client using servant-client, and turns out that this is the Accept header it creates by default if you want JSON...
Fyi, I don't recall why servan-client would intentionally send such an out-of-spec charset parameter; and in fact I'd rather want to have hackage-server reply with a 406 response to weed out broken clients than to silently fail; but here's what I do to deal with this non-compliant charset parameter being sent by servant-client in other code where I've been using servant-client to speak to Hackage's API
https://github.com/haskell-CI/hackage-matrix-builder/blob/master/src-lib/HackageApi.hs
Compare responses to
and
First one has
Content-Type: application/json; charset=utf-8
as expected, but the second one hasContent-Type: text/html; charset=utf-8
(and the response body would also be html in that case).