From bd4bb1557f35398a725cecb7aaeaddb383473698 Mon Sep 17 00:00:00 2001 From: Till Maas Date: Nov 25 2015 08:45:04 +0000 Subject: [PATCH 1/2] Add fuzzy logic for pretty detection References: #1 --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 19777df..7f835c0 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -95,7 +95,12 @@ def _get_pkg(branch, name): def _get_pretty(request): pretty = False - if request.query_string.lower() in ['pretty=1', 'pretty=true']: + query_string = request.query_string.lower() + if query_string in ['pretty=1', 'pretty=true']: + pretty = True + # Assume pretty if html is requested and pretty is not disabled + elif not query_string in ['pretty=0', 'pretty=false'] and \ + request.accept_mimetypes.best == "text/html": pretty = True return pretty From c36afdfd0b094937f4c6636e7822c6901b8c9759 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 25 2015 08:50:56 +0000 Subject: [PATCH 2/2] Fix the detection of the ACCEPT header to make things pretty in web browser --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index 7f835c0..d038363 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -99,8 +99,7 @@ def _get_pretty(request): if query_string in ['pretty=1', 'pretty=true']: pretty = True # Assume pretty if html is requested and pretty is not disabled - elif not query_string in ['pretty=0', 'pretty=false'] and \ - request.accept_mimetypes.best == "text/html": + elif 'text/html' in request.headers.get('ACCEPT', ''): pretty = True return pretty