OLD | NEW |
---|---|
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import re | 5 import re |
6 # F0401: 7,0: Unable to import 'webapp2' | 6 # F0401: 7,0: Unable to import 'webapp2' |
7 # pylint: disable=F0401 | 7 # pylint: disable=F0401 |
8 import webapp2 | 8 import webapp2 |
9 | 9 |
10 import cache | 10 import cache |
11 import config | 11 import config |
12 import content_processor | 12 import content_processor |
13 import content_type | 13 import content_type |
14 import pre_cacher | 14 import pre_cacher |
15 import file_reader | 15 import file_reader |
16 import zip_proxy | 16 import zip_proxy |
17 | 17 |
18 current_config = config.DEFAULT | 18 current_config = config.DEFAULT |
19 | 19 |
20 class MainPage(webapp2.RequestHandler): | 20 class MainPage(webapp2.RequestHandler): |
21 def get(self): | 21 def get(self): |
22 self.response.headers['Content-Type'] = 'text/plain' | 22 self.response.headers['Content-Type'] = 'text/plain' |
23 self.response.write(str(current_config)) | 23 self.response.write(str(current_config)) |
24 | 24 |
25 class Server(webapp2.RequestHandler): | 25 class Server(webapp2.RequestHandler): |
26 def get_file_hash(self, meta_content, path): | |
mnaganov (inactive)
2015/02/24 14:40:32
We should probably cache '(tag, path) -> hash' som
dgozman
2015/02/25 11:37:13
Done.
| |
27 for line in meta_content.split('\n'): | |
28 index = line.find(':') | |
29 if index != -1 and line[(index + 1):] == path: | |
30 return line[:index] | |
31 return None | |
32 | |
26 def get(self, tag_type, tag, path): | 33 def get(self, tag_type, tag, path): |
27 cache_key_name = '/res/%s/%s/%s' % (tag_type, tag, path) | 34 cache_key_name = '/res/%s/%s/%s' % (tag_type, tag, path) |
28 content = cache.get_content(cache_key_name) | 35 content = cache.get_content(cache_key_name) |
29 helper = config.ConfigHelper(current_config) | 36 helper = config.ConfigHelper(current_config) |
30 | 37 |
38 if not content and tag_type == 'file': | |
mnaganov (inactive)
2015/02/24 14:40:32
No, we shouldn't cache these resources under 'cach
dgozman
2015/02/25 11:37:13
Done.
| |
39 meta_file_name = helper.get_meta_path(tag) | |
40 meta_content = file_reader.read(helper, meta_file_name) | |
41 if not meta_content: | |
42 self.abort(404) | |
43 file_hash = self.get_file_hash(meta_content, path) | |
44 if not file_hash: | |
45 self.abort(404) | |
46 content = file_reader.read(helper, helper.get_hash_path(file_hash)) | |
47 if not content: | |
48 self.abort(404) | |
49 content = content_processor.process(path, content) | |
50 cache.set_content(cache_key_name, content) | |
51 | |
31 if not content: | 52 if not content: |
32 if tag_type == 'rev': | 53 if tag_type == 'rev': |
33 meta_file_name = helper.get_revision_path(tag) | 54 meta_file_name = helper.get_revision_path(tag) |
34 elif tag_type =='ver': | 55 elif tag_type =='ver': |
35 meta_file_name = helper.get_version_path(tag) | 56 meta_file_name = helper.get_version_path(tag) |
36 else: | 57 else: |
37 self.abort(404) | 58 self.abort(404) |
38 | 59 |
39 meta_content = file_reader.read(helper, meta_file_name) | 60 meta_content = file_reader.read(helper, meta_file_name) |
40 if meta_content: | 61 if meta_content: |
(...skipping 21 matching lines...) Expand all Loading... | |
62 return super(LegacyStatic, self).get('ver', match.group(1) + '0', path) | 83 return super(LegacyStatic, self).get('ver', match.group(1) + '0', path) |
63 else: | 84 else: |
64 self.abort(404) | 85 self.abort(404) |
65 | 86 |
66 app = webapp2.WSGIApplication( | 87 app = webapp2.WSGIApplication( |
67 [('/', MainPage), | 88 [('/', MainPage), |
68 ('/precache_url', pre_cacher.PreCacherFromUrl), | 89 ('/precache_url', pre_cacher.PreCacherFromUrl), |
69 webapp2.Route('/serve_<tag_type>/<tag>/<path:.*>', Server), | 90 webapp2.Route('/serve_<tag_type>/<tag>/<path:.*>', Server), |
70 webapp2.Route('/static/<version>/<path:.*>', LegacyStatic)], | 91 webapp2.Route('/static/<version>/<path:.*>', LegacyStatic)], |
71 debug=config.IS_DEV_APP_SERVER) | 92 debug=config.IS_DEV_APP_SERVER) |
OLD | NEW |