Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from appengine_wrappers import webapp | |
| 6 from cron_servlet import CronServlet | 5 from cron_servlet import CronServlet |
| 7 from render_servlet import RenderServlet | 6 from instance_servlet import InstanceServlet |
| 8 from servlet import Request | 7 from servlet import Servlet, Request, Response |
| 9 | 8 |
| 10 _SERVLETS = { | 9 _SERVLETS = { |
| 11 'cron': CronServlet, | 10 'cron': CronServlet, |
| 12 } | 11 } |
| 12 _DEFAULT_SERVLET = InstanceServlet.GetConstructor() | |
| 13 | 13 |
| 14 class Handler(webapp.RequestHandler): | 14 def _RedirectSpecialCases(path): |
| 15 def __init__(self, request, response): | 15 if not path or path == 'index.html': |
| 16 super(Handler, self).__init__(request, response) | 16 return Response.Redirect('http://developer.google.com/chrome') |
| 17 if path == 'apps.html': | |
| 18 return Response.Redirect('/apps/about_apps.html') | |
| 19 return None | |
| 17 | 20 |
| 18 def _RedirectSpecialCases(self, path): | 21 def _RedirectFromCodeDotGoogleDotCom(path): |
| 19 if not path or path == 'index.html': | 22 if not path.startswith(('http://code.google.com', 'https://code.google.com')): |
| 20 self.redirect('http://developer.google.com/chrome') | 23 return None |
| 21 return True | |
| 22 | 24 |
| 23 if path == 'apps.html': | 25 new_url = 'http://developer.chrome.com/' |
| 24 self.redirect('/apps/about_apps.html') | |
| 25 return True | |
| 26 | 26 |
| 27 return False | 27 # switch to https if necessary |
| 28 if path.startswith('https'): | |
| 29 new_url = new_url.replace('http', 'https', 1) | |
| 28 | 30 |
| 29 def _RedirectFromCodeDotGoogleDotCom(self, path): | 31 path = path.split('/') |
|
cduvall
2013/05/08 03:09:14
this is a little confusing reassigning the list of
not at google - send to devlin
2013/05/08 18:26:19
Oops. Done. Moving these back into instance method
| |
| 30 if (not self.request.url.startswith(('http://code.google.com', | 32 if len(path) > 0 and path[0] == 'chrome': |
| 31 'https://code.google.com'))): | 33 path.pop(0) |
| 32 return False | 34 for channel in BranchUtility.GetAllChannelNames(): |
| 35 if channel in path: | |
| 36 position = path.index(channel) | |
| 37 path.pop(position) | |
| 38 path.insert(0, channel) | |
| 39 new_url += '/'.join(path) | |
| 40 return Response.Redirect(new_url) | |
| 33 | 41 |
| 34 new_url = 'http://developer.chrome.com/' | 42 class Handler(Servlet): |
| 35 | 43 def Get(self): |
| 36 # switch to https if necessary | 44 path = self._request.path |
| 37 if (self.request.url.startswith('https')): | |
| 38 new_url = new_url.replace('http', 'https', 1) | |
| 39 | |
| 40 path = path.split('/') | |
| 41 if len(path) > 0 and path[0] == 'chrome': | |
| 42 path.pop(0) | |
| 43 for channel in BranchUtility.GetAllBranchNames(): | |
| 44 if channel in path: | |
| 45 position = path.index(channel) | |
| 46 path.pop(position) | |
| 47 path.insert(0, channel) | |
| 48 new_url += '/'.join(path) | |
| 49 self.redirect(new_url) | |
| 50 return True | |
| 51 | |
| 52 def get(self): | |
| 53 path, request, response = (self.request.path.lstrip('/'), | |
| 54 self.request, | |
| 55 self.response) | |
| 56 | 45 |
| 57 if path in ['favicon.ico', 'robots.txt']: | 46 if path in ['favicon.ico', 'robots.txt']: |
| 58 response.set_status(404) | 47 return Response.NotFound('') |
| 59 return | |
| 60 | 48 |
| 61 if self._RedirectSpecialCases(path): | 49 redirect = _RedirectSpecialCases(path) |
| 62 return | 50 if redirect is None: |
| 63 if self._RedirectFromCodeDotGoogleDotCom(path): | 51 redirect = _RedirectFromCodeDotGoogleDotCom(path) |
| 64 return | 52 if redirect is not None: |
| 53 return redirect | |
| 65 | 54 |
| 66 if path.startswith('_'): | 55 if path.startswith('_'): |
| 67 servlet_path = path[1:] | 56 servlet_path = path[1:] |
| 68 if servlet_path.find('/') == -1: | 57 if servlet_path.find('/') == -1: |
| 69 servlet_path += '/' | 58 servlet_path += '/' |
| 70 servlet_name, servlet_path = servlet_path.split('/', 1) | 59 servlet_name, servlet_path = servlet_path.split('/', 1) |
| 71 servlet = _SERVLETS.get(servlet_name) | 60 servlet = _SERVLETS.get(servlet_name) |
| 72 if servlet is None: | 61 if servlet is None: |
| 73 response.out.write('"%s" servlet not found' % servlet_path) | 62 return Response.NotFound('"%s" servlet not found' % servlet_path) |
| 74 response.set_status(404) | |
| 75 return | |
| 76 else: | 63 else: |
| 77 servlet_path = path | 64 servlet_path = path |
| 78 servlet = RenderServlet | 65 servlet = _DEFAULT_SERVLET |
| 79 | 66 |
| 80 servlet_response = servlet(Request(servlet_path, request.headers)).Get() | 67 return servlet(Request(servlet_path, self._request.headers)).Get() |
| 81 | |
| 82 response.out.write(servlet_response.content.ToString()) | |
| 83 response.headers.update(servlet_response.headers) | |
| 84 response.status = servlet_response.status | |
| OLD | NEW |