From c509da25712d47ee8115289be698f71ab84744d3 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sat, 24 Jul 2010 08:58:53 +0100 Subject: [PATCH] Require that json with higher q than text/html to switch to API --- flask_website/utils.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/flask_website/utils.py b/flask_website/utils.py index e2553c6c..a5bc4df2 100644 --- a/flask_website/utils.py +++ b/flask_website/utils.py @@ -92,8 +92,13 @@ def split_lines_wrapping(text, width=74, threshold=82): def request_wants_json(): - return request.accept_mimetypes \ - .best_match(['application/json', 'text/html']) == 'application/json' + # we only accept json if the quality of json is greater than the + # quality of text/html because text/html is preferred to support + # browsers that accept on */* + best = request.accept_mimetypes \ + .best_match(['application/json', 'text/html']) + return best == 'application/json' and \ + request.accept_mimetypes[best] > request.accept_mimetypes['text/html'] def requires_login(f):