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

Side by Side Diff: chrome/common/extensions/docs/server/chromeextensionsdocs.py

Issue 8942001: Force 'text/plain' rendering for HTML, CSS, and JS sample files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Startswith. Python is so clever. Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/docs/server/app.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import cgi 6 import cgi
7 import logging 7 import logging
8 import re 8 import re
9 import os 9 import os
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 url = url[0] % branch 69 url = url[0] % branch
70 else: 70 else:
71 url = url[0] 71 url = url[0]
72 logging.info("Path: " + self.request.path) 72 logging.info("Path: " + self.request.path)
73 logging.info("Url: " + url) 73 logging.info("Url: " + url)
74 try: 74 try:
75 result = urlfetch.fetch(url) 75 result = urlfetch.fetch(url)
76 if result.status_code != 200: 76 if result.status_code != 200:
77 logging.error("urlfetch failed: " + url) 77 logging.error("urlfetch failed: " + url)
78 # TODO(nickbaum): what should we do when the urlfetch fails? 78 # TODO(nickbaum): what should we do when the urlfetch fails?
79 # Files inside of samples should be rendered with content-type
80 # text/plain so that their source is visible when linked to. The only
81 # types we should serve as-is are images.
82 if (path.startswith("/examples") and
83 not (result.headers['content-type'].startswith('image/') or
84 result.headers['Content-Type'].startswith('image/'))):
85 result.headers['content-type'] = 'text/plain'
79 except: 86 except:
80 logging.error("urlfetch failed: " + url) 87 logging.error("urlfetch failed: " + url)
81 # TODO(nickbaum): what should we do when the urlfetch fails? 88 # TODO(nickbaum): what should we do when the urlfetch fails?
82 try: 89 try:
83 if not memcache.add(path, result, DEFAULT_CACHE_TIME): 90 if not memcache.add(path, result, DEFAULT_CACHE_TIME):
84 logging.error("Memcache set failed.") 91 logging.error("Memcache set failed.")
85 except: 92 except:
86 logging.error("Memcache set failed.") 93 logging.error("Memcache set failed.")
87 for key in result.headers: 94 for key in result.headers:
88 self.response.headers[key] = result.headers[key] 95 self.response.headers[key] = result.headers[key]
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 ('/.*', MainPage), 272 ('/.*', MainPage),
266 ], debug=False) 273 ], debug=False)
267 274
268 275
269 def main(): 276 def main():
270 run_wsgi_app(application) 277 run_wsgi_app(application)
271 278
272 279
273 if __name__ == '__main__': 280 if __name__ == '__main__':
274 main() 281 main()
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server/app.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698