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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « appengine/monorail/framework/reap.py ('k') | appengine/monorail/framework/servlet.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/framework/registerpages_helpers.py
diff --git a/appengine/monorail/framework/registerpages_helpers.py b/appengine/monorail/framework/registerpages_helpers.py
new file mode 100644
index 0000000000000000000000000000000000000000..5a86336aabf1589bdeb65cba74d898df3467f438
--- /dev/null
+++ b/appengine/monorail/framework/registerpages_helpers.py
@@ -0,0 +1,72 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""This file sets up all the urls for monorail pages."""
+
+
+import httplib
+import logging
+
+import webapp2
+
+
+def MakeRedirect(redirect_to_this_uri, permanent=True):
+ """Return a new request handler class that redirects to the given URL."""
+
+ class Redirect(webapp2.RequestHandler):
+ """Redirect is a response handler that issues a redirect to another URI."""
+
+ def get(self, **_kw):
+ """Send the 301/302 response code and write the Location: redirect."""
+ self.response.location = redirect_to_this_uri
+ self.response.headers.add('Strict-Transport-Security',
+ 'max-age=31536000; includeSubDomains')
+ self.response.status = (
+ httplib.MOVED_PERMANENTLY if permanent else httplib.FOUND)
+
+ return Redirect
+
+
+def MakeRedirectInScope(uri_in_scope, scope, permanent=True):
+ """Redirect to a URI within a given scope, e.g., per project or user.
+
+ Args:
+ uri_in_scope: a uri within a project or user starting with a slash.
+ scope: a string indicating the uri-space scope:
+ p for project pages
+ u for user pages
+ g for group pages
+ permanent: True for a HTTP 301 permanently moved response code,
+ otherwise a HTTP 302 temporarily moved response will be used.
+
+ Example:
+ self._SetupProjectPage(
+ redirect.MakeRedirectInScope('/newpage', 'p'), '/oldpage')
+
+ Returns:
+ A class that can be used with webapp2.
+ """
+ assert uri_in_scope.startswith('/')
+
+ class RedirectInScope(webapp2.RequestHandler):
+ """A handler that redirects to another URI in the same scope."""
+
+ def get(self, **_kw):
+ """Send the 301/302 response code and write the Location: redirect."""
+ split_path = self.request.path.lstrip('/').split('/')
+ if len(split_path) > 1:
+ project_or_user = split_path[1]
+ url = '//%s/%s/%s%s' % (
+ self.request.host, scope, project_or_user, uri_in_scope)
+ self.response.location = url
+ else:
+ self.response.location = '/'
+
+ self.response.headers.add('Strict-Transport-Security',
+ 'max-age=31536000; includeSubDomains')
+ self.response.status = (
+ httplib.MOVED_PERMANENTLY if permanent else httplib.FOUND)
+
+ return RedirectInScope
« 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