mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-28 16:28:01 -05:00
See you later RewriteMiddleware.
This appears to only have been be used for obsolete .js URL forms of widgets.
This commit is contained in:
@@ -38,7 +38,6 @@ from pylons.wsgiapp import PylonsApp
|
||||
from routes.middleware import RoutesMiddleware
|
||||
|
||||
from r2.config.environment import load_environment
|
||||
from r2.config.rewrites import rewrites
|
||||
from r2.config.extensions import extension_mapping, set_extension
|
||||
from r2.lib.utils import is_subdomain
|
||||
|
||||
@@ -264,26 +263,14 @@ class ExtensionMiddleware(object):
|
||||
|
||||
return self.app(environ, start_response)
|
||||
|
||||
class RewriteMiddleware(object):
|
||||
class FullPathMiddleware(object):
|
||||
# Debt: we have a lot of middleware which (unfortunately) modify the
|
||||
# global URL PATH_INFO string. To work with the original request URL, we
|
||||
# save it to a different location here.
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
|
||||
def rewrite(self, regex, out_template, input):
|
||||
m = regex.match(input)
|
||||
out = out_template
|
||||
if m:
|
||||
for num, group in enumerate(m.groups('')):
|
||||
out = out.replace('$%s' % (num + 1), group)
|
||||
return out
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
path = environ['PATH_INFO']
|
||||
for r in rewrites:
|
||||
newpath = self.rewrite(r[0], r[1], path)
|
||||
if newpath:
|
||||
environ['PATH_INFO'] = newpath
|
||||
break
|
||||
|
||||
environ['FULLPATH'] = environ.get('PATH_INFO')
|
||||
qs = environ.get('QUERY_STRING')
|
||||
if qs:
|
||||
@@ -468,8 +455,7 @@ def make_app(global_conf, full_stack=True, **app_conf):
|
||||
static_cascade.insert(0, plugin_static_apps)
|
||||
app = Cascade(static_cascade)
|
||||
|
||||
#add the rewrite rules
|
||||
app = RewriteMiddleware(app)
|
||||
app = FullPathMiddleware(app)
|
||||
|
||||
if not g.config['uncompressedJS'] and g.config['debug']:
|
||||
static_fallback = StaticTestMiddleware(static_app, g.config['static_path'], g.config['static_domain'])
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
# The contents of this file are subject to the Common Public Attribution
|
||||
# License Version 1.0. (the "License"); you may not use this file except in
|
||||
# compliance with the License. You may obtain a copy of the License at
|
||||
# http://code.reddit.com/LICENSE. The License is based on the Mozilla Public
|
||||
# License Version 1.1, but Sections 14 and 15 have been added to cover use of
|
||||
# software over a computer network and provide for limited attribution for the
|
||||
# Original Developer. In addition, Exhibit A has been modified to be consistent
|
||||
# with Exhibit B.
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
||||
# the specific language governing rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is reddit.
|
||||
#
|
||||
# The Original Developer is the Initial Developer. The Initial Developer of
|
||||
# the Original Code is reddit Inc.
|
||||
#
|
||||
# All portions of the code written by reddit are Copyright (c) 2006-2013 reddit
|
||||
# Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
import re
|
||||
|
||||
rewrites = (#these first two rules prevent the .embed rewrite from
|
||||
#breaking other js that should work
|
||||
("\A/_(.*)", "/_$1"),
|
||||
("\A/static/(.*\.js)", "/static/$1"),
|
||||
#This next rewrite makes it so that all the embed stuff works.
|
||||
("\A(.*)(?<!button)(?<!buttonlite)(\.js)\Z", "$1.embed"))
|
||||
|
||||
rewrites = tuple((re.compile(r[0]), r[1]) for r in rewrites)
|
||||
Reference in New Issue
Block a user