Require that json with higher q than text/html to switch to API

This commit is contained in:
Armin Ronacher 2010-07-24 08:58:53 +01:00
parent 3ec22fca46
commit c509da2571

View file

@ -92,8 +92,13 @@ def split_lines_wrapping(text, width=74, threshold=82):
def request_wants_json(): def request_wants_json():
return request.accept_mimetypes \ # we only accept json if the quality of json is greater than the
.best_match(['application/json', 'text/html']) == 'application/json' # 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): def requires_login(f):