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.
This commit is contained in:
Max Goodman
2011-12-08 23:25:24 -08:00
parent 1950fd6499
commit facf7f7930

View File

@@ -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'