Better api request detection

See commit log for details. tl;dr for a "did the client explicitly request `application/json`" check, we can't use the newer `request.accept?()` method, but the code here matches the intent of the old check. Also refactors it.