Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: multiplexer.py

Issue 5747446760079360: Issue 402 - Use a redirector script for downloads, not a direct link (Closed)
Patch Set: Created Sept. 15, 2014, 11:39 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « multiplexer.fcgi ('k') | sitescripts/extensions/web/__init__.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: multiplexer.py
===================================================================
--- a/multiplexer.py
+++ b/multiplexer.py
@@ -11,26 +11,33 @@
# Adblock Plus is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+import re
import flask
from sitescripts.web import handlers
from urlparse import urlparse
app = flask.Flask(__name__)
@app.route("/<path:path>", methods = ["GET", "POST"])
def multiplex(path):
request_url = urlparse(flask.request.url)
+ if 'SERVER_ADDR' not in flask.request.environ:
+ flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME']
+ if 'REQUEST_URI' not in flask.request.environ:
+ flask.request.environ['REQUEST_URI'] = flask.request.url
+
request_path = request_url.path
if request_path in handlers:
- if 'SERVER_ADDR' not in flask.request.environ:
- flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME']
return handlers[request_path]
+ request_dir = re.sub(r'[^/]+$', '', request_path)
+ if request_dir in handlers:
+ return handlers[request_dir]
return flask.abort(404)
if __name__ == "__main__":
app.run(debug=True)
« no previous file with comments | « multiplexer.fcgi ('k') | sitescripts/extensions/web/__init__.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld