Docserver: Fix broken redirect on code.google.com/chrome/

BUG=379668
R=kalman
NOTRY=TRUE

Review URL: https://codereview.chromium.org/311793002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274789 0039d316-1c4b-4281-b951-d872f2087c98
parent 25274993
application: chrome-apps-doc application: chrome-apps-doc
version: 3-25-0 version: 3-25-1
runtime: python27 runtime: python27
api_version: 1 api_version: 1
threadsafe: false threadsafe: false
......
...@@ -2,4 +2,4 @@ cron: ...@@ -2,4 +2,4 @@ cron:
- description: Repopulates all cached data. - description: Repopulates all cached data.
url: /_cron url: /_cron
schedule: every 5 minutes schedule: every 5 minutes
target: 3-25-0 target: 3-25-1
...@@ -91,7 +91,7 @@ class RenderServlet(Servlet): ...@@ -91,7 +91,7 @@ class RenderServlet(Servlet):
if redirect is not None: if redirect is not None:
# Absolute redirects stay absolute, relative redirects are relative to # Absolute redirects stay absolute, relative redirects are relative to
# |serve_from|; all redirects eventually need to be *served* as absolute. # |serve_from|; all redirects eventually need to be *served* as absolute.
if not redirect.startswith('/'): if not redirect.startswith(('/', 'http://', 'https://')):
redirect = '/' + posixpath.join(serve_from, redirect) redirect = '/' + posixpath.join(serve_from, redirect)
return Response.Redirect(redirect, permanent=False) return Response.Redirect(redirect, permanent=False)
......
...@@ -19,8 +19,8 @@ class _RenderServletDelegate(RenderServlet.Delegate): ...@@ -19,8 +19,8 @@ class _RenderServletDelegate(RenderServlet.Delegate):
class RenderServletTest(unittest.TestCase): class RenderServletTest(unittest.TestCase):
def _Render(self, path, headers=None): def _Render(self, path, headers=None, host=None):
return RenderServlet(Request.ForTest(path, headers=headers), return RenderServlet(Request.ForTest(path, headers=headers, host=host),
_RenderServletDelegate()).Get() _RenderServletDelegate()).Get()
def testExtensionAppRedirect(self): def testExtensionAppRedirect(self):
...@@ -34,6 +34,16 @@ class RenderServletTest(unittest.TestCase): ...@@ -34,6 +34,16 @@ class RenderServletTest(unittest.TestCase):
Response.Redirect('/extensions/storage', permanent=True), Response.Redirect('/extensions/storage', permanent=True),
self._Render('%s/extensions/storage' % channel)) self._Render('%s/extensions/storage' % channel))
def testOldHostsRedirect(self):
self.assertEqual(
Response.Redirect('https://developer.chrome.com/extensions',
permanent=False),
self._Render('/chrome/extensions', host='http://code.google.com'))
self.assertEqual(
Response.Redirect('https://developer.chrome.com/extensions',
permanent=False),
self._Render('/chrome/extensions', host='https://code.google.com'))
def testNotFound(self): def testNotFound(self):
def create_404_response(real_path): def create_404_response(real_path):
real_404 = self._Render(real_path) real_404 = self._Render(real_path)
......
...@@ -32,8 +32,8 @@ class Request(object): ...@@ -32,8 +32,8 @@ class Request(object):
self.headers = RequestHeaders(headers) self.headers = RequestHeaders(headers)
@staticmethod @staticmethod
def ForTest(path, host='http://developer.chrome.com', headers=None): def ForTest(path, host=None, headers=None):
return Request(path, host, headers or {}) return Request(path, host or 'http://developer.chrome.com', headers or {})
def __repr__(self): def __repr__(self):
return 'Request(path=%s, host=%s, headers=%s)' % ( return 'Request(path=%s, host=%s, headers=%s)' % (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment