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

Side by Side Diff: multiplexer.py

Issue 5747446760079360: Issue 402 - Use a redirector script for downloads, not a direct link (Closed)
Patch Set: Created Sept. 9, 2014, 10:01 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « multiplexer.fcgi ('k') | sitescripts/extensions/web/__init__.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 # This file is part of the Adblock Plus web scripts, 4 # This file is part of the Adblock Plus web scripts,
5 # Copyright (C) 2006-2014 Eyeo GmbH 5 # Copyright (C) 2006-2014 Eyeo GmbH
6 # 6 #
7 # Adblock Plus is free software: you can redistribute it and/or modify 7 # Adblock Plus is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 3 as 8 # it under the terms of the GNU General Public License version 3 as
9 # published by the Free Software Foundation. 9 # published by the Free Software Foundation.
10 # 10 #
11 # Adblock Plus is distributed in the hope that it will be useful, 11 # Adblock Plus is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details. 14 # GNU General Public License for more details.
15 # 15 #
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 17 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
18 18
19 import re
19 import flask 20 import flask
20 from sitescripts.web import handlers 21 from sitescripts.web import handlers
21 from urlparse import urlparse 22 from urlparse import urlparse
22 23
23 app = flask.Flask(__name__) 24 app = flask.Flask(__name__)
24 25
25 @app.route("/<path:path>", methods = ["GET", "POST"]) 26 @app.route("/<path:path>", methods = ["GET", "POST"])
26 def multiplex(path): 27 def multiplex(path):
27 request_url = urlparse(flask.request.url) 28 request_url = urlparse(flask.request.url)
29 if 'SERVER_ADDR' not in flask.request.environ:
30 flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME']
31 if 'REQUEST_URI' not in flask.request.environ:
32 flask.request.environ['REQUEST_URI'] = flask.request.url
33
28 request_path = request_url.path 34 request_path = request_url.path
29 if request_path in handlers: 35 if request_path in handlers:
30 if 'SERVER_ADDR' not in flask.request.environ:
31 flask.request.environ['SERVER_ADDR'] = flask.request.environ['SERVER_NAME' ]
32 return handlers[request_path] 36 return handlers[request_path]
37 request_dir = re.sub(r'[^/]+$', '', request_path)
38 if request_dir in handlers:
39 return handlers[request_dir]
33 return flask.abort(404) 40 return flask.abort(404)
34 41
35 if __name__ == "__main__": 42 if __name__ == "__main__":
36 app.run(debug=True) 43 app.run(debug=True)
OLDNEW
« 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