OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 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 from fnmatch import fnmatch | 5 from fnmatch import fnmatch |
6 import logging | 6 import logging |
7 import mimetypes | 7 import mimetypes |
8 from urlparse import urlsplit | 8 from urlparse import urlsplit |
9 | 9 |
| 10 from data_source_registry import CreateDataSources |
10 from file_system import FileNotFoundError | 11 from file_system import FileNotFoundError |
11 from servlet import Servlet, Response | 12 from servlet import Servlet, Response |
12 import svn_constants | 13 import svn_constants |
13 | 14 |
14 def _IsBinaryMimetype(mimetype): | 15 def _IsBinaryMimetype(mimetype): |
15 return any( | 16 return any( |
16 mimetype.startswith(prefix) for prefix in ['audio', 'image', 'video']) | 17 mimetype.startswith(prefix) for prefix in ['audio', 'image', 'video']) |
17 | 18 |
18 class RenderServlet(Servlet): | 19 class RenderServlet(Servlet): |
19 '''Servlet which renders templates. | 20 '''Servlet which renders templates. |
(...skipping 22 matching lines...) Expand all Loading... |
42 if redirect is not None: | 43 if redirect is not None: |
43 return Response.Redirect(redirect) | 44 return Response.Redirect(redirect) |
44 | 45 |
45 canonical_result = server_instance.path_canonicalizer.Canonicalize(path) | 46 canonical_result = server_instance.path_canonicalizer.Canonicalize(path) |
46 redirect = canonical_result.path.lstrip('/') | 47 redirect = canonical_result.path.lstrip('/') |
47 if path != redirect: | 48 if path != redirect: |
48 return Response.Redirect('/' + redirect, | 49 return Response.Redirect('/' + redirect, |
49 permanent=canonical_result.permanent) | 50 permanent=canonical_result.permanent) |
50 | 51 |
51 templates = server_instance.template_data_source_factory.Create( | 52 templates = server_instance.template_data_source_factory.Create( |
52 self._request, path) | 53 self._request, |
| 54 path, |
| 55 CreateDataSources(server_instance, self._request)) |
53 | 56 |
54 content = None | 57 content = None |
55 content_type = None | 58 content_type = None |
56 | 59 |
57 try: | 60 try: |
58 # At this point, any valid paths ending with '/' have been redirected. | 61 # At this point, any valid paths ending with '/' have been redirected. |
59 # Therefore, the response should be a 404 Not Found. | 62 # Therefore, the response should be a 404 Not Found. |
60 if path.endswith('/'): | 63 if path.endswith('/'): |
61 pass | 64 pass |
62 elif fnmatch(path, 'extensions/examples/*.zip'): | 65 elif fnmatch(path, 'extensions/examples/*.zip'): |
(...skipping 27 matching lines...) Expand all Loading... |
90 return Response.NotFound(content, headers=headers) | 93 return Response.NotFound(content, headers=headers) |
91 | 94 |
92 if not content: | 95 if not content: |
93 logging.error('%s had empty content' % path) | 96 logging.error('%s had empty content' % path) |
94 | 97 |
95 headers.update({ | 98 headers.update({ |
96 'content-type': content_type, | 99 'content-type': content_type, |
97 'cache-control': 'max-age=300', | 100 'cache-control': 'max-age=300', |
98 }) | 101 }) |
99 return Response.Ok(content, headers=headers) | 102 return Response.Ok(content, headers=headers) |
OLD | NEW |