mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-31 01:38:08 -05:00
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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user