From facf7f7930a727c661bb2f3efc1f40329fbdb469 Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Thu, 8 Dec 2011 23:25:24 -0800 Subject: [PATCH] Simplify and fix extension mapping lookups. This fixes an issue introduced by 825e644f526a5570590c4648e28c1beda4d79e17 in which the extension mapping changes from a tuple to a dict. Since dicts don't have a guaranteed ordering, that change affected the behavior of the .json-compact extension. --- r2/r2/config/middleware.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/r2/r2/config/middleware.py b/r2/r2/config/middleware.py index 9cb1a19cf..4dec5e9a5 100644 --- a/r2/r2/config/middleware.py +++ b/r2/r2/config/middleware.py @@ -378,14 +378,19 @@ class ExtensionMiddleware(object): def __call__(self, environ, start_response): path = environ['PATH_INFO'] + fname, sep, path_ext = path.rpartition('.') domain_ext = environ.get('reddit-domain-extension') - for ext, val in extension_mapping.iteritems(): - if ext == domain_ext or path.endswith('.' + ext): - set_extension(environ, ext) - #strip off the extension - if path.endswith('.' + ext): - environ['PATH_INFO'] = path[:-(len(ext) + 1)] - break + + ext = None + if path_ext in extension_mapping: + ext = path_ext + # Strip off the extension. + environ['PATH_INFO'] = path[:-(len(ext) + 1)] + elif domain_ext in extension_mapping: + ext = domain_ext + + if ext: + set_extension(environ, ext) else: environ['render_style'] = 'html' environ['content_type'] = 'text/html; charset=UTF-8'