Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: appengine/monorail/framework/registerpages_helpers.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/monorail/framework/reap.py ('k') | appengine/monorail/framework/servlet.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """This file sets up all the urls for monorail pages."""
7
8
9 import httplib
10 import logging
11
12 import webapp2
13
14
15 def MakeRedirect(redirect_to_this_uri, permanent=True):
16 """Return a new request handler class that redirects to the given URL."""
17
18 class Redirect(webapp2.RequestHandler):
19 """Redirect is a response handler that issues a redirect to another URI."""
20
21 def get(self, **_kw):
22 """Send the 301/302 response code and write the Location: redirect."""
23 self.response.location = redirect_to_this_uri
24 self.response.headers.add('Strict-Transport-Security',
25 'max-age=31536000; includeSubDomains')
26 self.response.status = (
27 httplib.MOVED_PERMANENTLY if permanent else httplib.FOUND)
28
29 return Redirect
30
31
32 def MakeRedirectInScope(uri_in_scope, scope, permanent=True):
33 """Redirect to a URI within a given scope, e.g., per project or user.
34
35 Args:
36 uri_in_scope: a uri within a project or user starting with a slash.
37 scope: a string indicating the uri-space scope:
38 p for project pages
39 u for user pages
40 g for group pages
41 permanent: True for a HTTP 301 permanently moved response code,
42 otherwise a HTTP 302 temporarily moved response will be used.
43
44 Example:
45 self._SetupProjectPage(
46 redirect.MakeRedirectInScope('/newpage', 'p'), '/oldpage')
47
48 Returns:
49 A class that can be used with webapp2.
50 """
51 assert uri_in_scope.startswith('/')
52
53 class RedirectInScope(webapp2.RequestHandler):
54 """A handler that redirects to another URI in the same scope."""
55
56 def get(self, **_kw):
57 """Send the 301/302 response code and write the Location: redirect."""
58 split_path = self.request.path.lstrip('/').split('/')
59 if len(split_path) > 1:
60 project_or_user = split_path[1]
61 url = '//%s/%s/%s%s' % (
62 self.request.host, scope, project_or_user, uri_in_scope)
63 self.response.location = url
64 else:
65 self.response.location = '/'
66
67 self.response.headers.add('Strict-Transport-Security',
68 'max-age=31536000; includeSubDomains')
69 self.response.status = (
70 httplib.MOVED_PERMANENTLY if permanent else httplib.FOUND)
71
72 return RedirectInScope
OLDNEW
« no previous file with comments | « appengine/monorail/framework/reap.py ('k') | appengine/monorail/framework/servlet.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698