From 60f293e8a852981c80250f7a1671509c9edd26c3 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Fri, 25 Nov 2011 21:27:52 -0800 Subject: [PATCH] Use paste's parser for Accept-Encoding check. --- r2/r2/lib/template_helpers.py | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/r2/r2/lib/template_helpers.py b/r2/r2/lib/template_helpers.py index 54197c37b..410889ba1 100644 --- a/r2/r2/lib/template_helpers.py +++ b/r2/r2/lib/template_helpers.py @@ -33,31 +33,12 @@ import random import urlparse from pylons import g, c from pylons.i18n import _, ungettext +from paste.util.mimeparse import desired_matches def is_encoding_acceptable(encoding_to_check): - """"Check if a content encoding is acceptable to the user agent. - - An encoding is determined acceptable if the encoding (or the special '*' encoding) - is specified in the Accept-Encoding header with a quality value > 0. - """ + "Check if a content encoding is acceptable to the user agent." header = request.headers.get('Accept-Encoding', '') - encodings = header.split(',') - - for value in encodings: - if ';' not in value: - name = value.strip() - else: - coding_name, quality = value.split(';') - if '=' not in quality: - continue - q, value = quality.split('=') - if float(value) == 0: - continue - name = coding_name.strip() - - if name in (encoding_to_check, '*'): - return True - return False + return 'gzip' in desired_matches(['gzip'], header) def static(path, allow_gzip=True): """