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

Unified Diff: chrome/common/extensions/docs/server2/patch_servlet.py

Issue 14125010: Docserver: Add support for viewing docs with a codereview patch applied (Closed) Base URL: https://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 7 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
Index: chrome/common/extensions/docs/server2/patch_servlet.py
===================================================================
--- chrome/common/extensions/docs/server2/patch_servlet.py (revision 0)
+++ chrome/common/extensions/docs/server2/patch_servlet.py (revision 0)
@@ -0,0 +1,44 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from appengine_wrappers import IsDevServer
+from render_servlet import RenderServlet
+from rietveld_patcher import RietveldPatcherError
+from server_instance import ServerInstance
+from servlet import Request, Response, Servlet
+
+class PatchServlet(Servlet):
+ '''Servlet which renders patched docs.
+ '''
+
+ def Get(self):
+ path_with_issue = self._request.path
+ if '/' in path_with_issue:
not at google - send to devlin 2013/05/07 05:45:40 well if there isn't a '/' then it's a malformed, s
方觉(Fang Jue) 2013/05/07 06:03:55 Done.
+ issue, real_path = path_with_issue.split('/', 1)
+ else:
+ issue, real_path = path_with_issue, ''
+
+ constructor = (ServerInstance.CreateOnline if IsDevServer() else
+ ServerInstance.GetOrCreateOffline)
+ server_instance = constructor('trunk',
+ '/_patch/%s/static' % issue,
+ issue)
+ fake_path = '/trunk/%s' % real_path
+
+ try:
+ response = RenderServlet(Request(
+ fake_path,
+ self._request.headers)).Get(server_instance)
+ # Disable cache for patched content.
not at google - send to devlin 2013/05/07 05:45:40 you can do "response.headers.pop('cache-control',
方觉(Fang Jue) 2013/05/07 06:03:55 Done.
+ if response.headers.get('cache-control'):
+ del response.headers['cache-control']
+ except RietveldPatcherError as e:
+ response = Response.NotFound(e.message, {'Content-Type': 'text/plain'})
not at google - send to devlin 2013/05/07 05:45:40 would kind of rather prefer to leave the content-t
方觉(Fang Jue) 2013/05/07 06:03:55 I just don't want any HTML injected in URL to be r
not at google - send to devlin 2013/05/07 06:17:21 Ok cool. We should either enforce that there's a c
+
+ if response.IsRedirect():
+ url = response.headers['Location']
+ if url.startswith('/trunk/'):
+ url = url.split('/trunk', 1)[1]
+ response.headers['Location'] = '/_patch/%s%s' % (issue, url)
+ return response
Property changes on: chrome/common/extensions/docs/server2/patch_servlet.py
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698