OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 from fnmatch import fnmatch | 5 from fnmatch import fnmatch |
6 import mimetypes | 6 import mimetypes |
7 import os | 7 import os |
8 | 8 |
9 from file_system import FileNotFoundError | 9 from file_system import FileNotFoundError |
10 import compiled_file_system as compiled_fs | 10 import compiled_file_system as compiled_fs |
(...skipping 25 matching lines...) Expand all Loading... | |
36 result = self._cache.GetFromFile(STATIC_DIR_PREFIX + '/' + path, | 36 result = self._cache.GetFromFile(STATIC_DIR_PREFIX + '/' + path, |
37 binary=_IsBinaryMimetype(mimetype)) | 37 binary=_IsBinaryMimetype(mimetype)) |
38 except FileNotFoundError: | 38 except FileNotFoundError: |
39 return None | 39 return None |
40 response.headers['content-type'] = mimetype | 40 response.headers['content-type'] = mimetype |
41 return result | 41 return result |
42 | 42 |
43 def Get(self, path, request, response): | 43 def Get(self, path, request, response): |
44 # TODO(cduvall): bundle up all the request-scoped data into a single object. | 44 # TODO(cduvall): bundle up all the request-scoped data into a single object. |
45 templates = self._template_data_source_factory.Create(request, path) | 45 templates = self._template_data_source_factory.Create(request, path) |
46 | |
cduvall
2013/03/21 18:43:53
Give back my newline!
epeterson
2013/03/25 19:35:11
Done. Sorry!
| |
47 content = None | 46 content = None |
48 if fnmatch(path, 'extensions/examples/*.zip'): | 47 if fnmatch(path, 'extensions/examples/*.zip'): |
49 try: | 48 try: |
50 content = self._example_zipper.Create( | 49 content = self._example_zipper.Create( |
51 path[len('extensions/'):-len('.zip')]) | 50 path[len('extensions/'):-len('.zip')]) |
52 response.headers['content-type'] = 'application/zip' | 51 response.headers['content-type'] = 'application/zip' |
53 except FileNotFoundError: | 52 except FileNotFoundError: |
54 content = None | 53 content = None |
55 elif path.startswith('extensions/examples/'): | 54 elif path.startswith('extensions/examples/'): |
56 mimetype = mimetypes.guess_type(path)[0] or 'text/plain' | 55 mimetype = mimetypes.guess_type(path)[0] or 'text/plain' |
57 try: | 56 try: |
58 content = self._cache.GetFromFile( | 57 content = self._cache.GetFromFile( |
59 '%s/%s' % (DOCS_PATH, path[len('extensions/'):]), | 58 '%s/%s' % (DOCS_PATH, path[len('extensions/'):]), |
60 binary=_IsBinaryMimetype(mimetype)) | 59 binary=_IsBinaryMimetype(mimetype)) |
61 response.headers['content-type'] = 'text/plain' | 60 response.headers['content-type'] = 'text/plain' |
62 except FileNotFoundError: | 61 except FileNotFoundError: |
63 content = None | 62 content = None |
64 elif path.startswith('static/'): | 63 elif path.startswith('static/'): |
65 content = self._FetchStaticResource(path, response) | 64 content = self._FetchStaticResource(path, response) |
66 elif path.endswith('.html'): | 65 elif path.endswith('.html'): |
67 content = templates.Render(path) | 66 content = templates.Render(path) |
68 | 67 |
69 response.headers['x-frame-options'] = 'sameorigin' | 68 response.headers['x-frame-options'] = 'sameorigin' |
70 if content: | 69 if content: |
71 response.headers['cache-control'] = 'max-age=300' | 70 response.headers['cache-control'] = 'max-age=300' |
72 response.out.write(content) | 71 response.out.write(content) |
73 else: | 72 else: |
74 response.set_status(404); | 73 response.set_status(404); |
75 response.out.write(templates.Render('404')) | 74 response.out.write(templates.Render('404')) |
OLD | NEW |