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

Side by Side Diff: scripts/redirector.py

Issue 22898006: In the dev server, files are not cached (Closed) Base URL: https://github.com/dart-lang/dartdoc-viewer.git@master
Patch Set: Fixed bad python string style Created 7 years, 4 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 | « no previous file | 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 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 # for details. All rights reserved. Use of this source code is governed by a 2 # for details. All rights reserved. Use of this source code is governed by a
3 # BSD-style license that can be found in the LICENSE file. 3 # BSD-style license that can be found in the LICENSE file.
4 4
5 # This script is used to redirect HTTP requests to retrieve the correct 5 # This script is used to redirect HTTP requests to retrieve the correct
6 # files from Google Cloud Storage. 6 # files from Google Cloud Storage.
7 7
8 import logging 8 import logging
9 import urllib2 9 import urllib2
10 import os 10 import os
(...skipping 24 matching lines...) Expand all
35 if os.environ['SERVER_SOFTWARE'].startswith('Development'): 35 if os.environ['SERVER_SOFTWARE'].startswith('Development'):
36 self.GetLocal() 36 self.GetLocal()
37 else: 37 else:
38 self.GetGoogleStorage() 38 self.GetGoogleStorage()
39 39
40 def GetLocal(self): 40 def GetLocal(self):
41 """ Used for local, dev server HTTP requests. """ 41 """ Used for local, dev server HTTP requests. """
42 path = LOCAL_PATH + self.request.path[len('docs/'):] 42 path = LOCAL_PATH + self.request.path[len('docs/'):]
43 with open(path, 'r') as file: 43 with open(path, 'r') as file:
44 result = file.read() 44 result = file.read()
45 self.HandleCacheAge(path) 45 # The cache age should be zero seconds if being run locally.
46 self.response.headers['Cache-Control'] = 'max-age=%d,s-maxage=%d' % (0, 0)
46 self.response.out.write(result) 47 self.response.out.write(result)
47 48
48 def GetGoogleStorage(self): 49 def GetGoogleStorage(self):
49 """ Used for App Engine HTTP requests. """ 50 """ Used for App Engine HTTP requests. """
50 version_key = blobstore.create_gs_key(GS_VERSION) 51 version_key = blobstore.create_gs_key(GS_VERSION)
51 blob_reader = blobstore.BlobReader(version_key) 52 blob_reader = blobstore.BlobReader(version_key)
52 version = blob_reader.read() 53 version = blob_reader.read()
53 path = GS_PATH + version + self.request.path[len('docs/'):] 54 path = GS_PATH + version + self.request.path[len('docs/'):]
54 gs_key = blobstore.create_gs_key(path) 55 gs_key = blobstore.create_gs_key(path)
55 self.HandleCacheAge(path) 56 self.HandleCacheAge(path)
56 self.send_blob(gs_key) 57 self.send_blob(gs_key)
57 58
58 def HandleCacheAge(self, path): 59 def HandleCacheAge(self, path):
59 """ Assigns a document a length of time it will live in the cache. """ 60 """ Assigns a document a length of time it will live in the cache. """
60 age = None 61 age = None
61 if re.search(r'(png|jpg)$', path): 62 if re.search(r'(png|jpg)$', path):
62 age = ONE_DAY 63 age = ONE_DAY
63 elif path.endswith('.ico'): 64 elif path.endswith('.ico'):
64 age = ONE_WEEK 65 age = ONE_WEEK
65 else: 66 else:
66 age = ONE_HOUR 67 age = ONE_HOUR
67 self.response.headers['Cache-Control'] = 'max-age=' + \ 68 self.response.headers['Cache-Control'] = 'max-age=%d,s-maxage=%d' % \
68 str(age) + ',s-maxage=' + str(age) 69 (age, age)
69 70
70 application = WSGIApplication( 71 application = WSGIApplication(
71 [ 72 [
72 ('/docs/.*', RequestHandler), 73 ('/docs/.*', RequestHandler),
73 ], debug=True) 74 ], debug=True)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698