| 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 import os | 8 import os |
| 9 import traceback | 9 import traceback |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 content_type = mimetype | 83 content_type = mimetype |
| 84 elif path.endswith('.html'): | 84 elif path.endswith('.html'): |
| 85 content = templates.Render(path) | 85 content = templates.Render(path) |
| 86 content_type = 'text/html' | 86 content_type = 'text/html' |
| 87 except FileNotFoundError as e: | 87 except FileNotFoundError as e: |
| 88 logging.warning(traceback.format_exc()) | 88 logging.warning(traceback.format_exc()) |
| 89 content = None | 89 content = None |
| 90 | 90 |
| 91 headers = {'x-frame-options': 'sameorigin'} | 91 headers = {'x-frame-options': 'sameorigin'} |
| 92 if content is None: | 92 if content is None: |
| 93 return Response.NotFound(templates.Render('404'), headers=headers) | 93 doc_class = path.split('/', 1)[0] |
| 94 content = templates.Render('%s/404' % doc_class) |
| 95 if not content: |
| 96 content = templates.Render('extensions/404') |
| 97 return Response.NotFound(content, headers=headers) |
| 94 | 98 |
| 95 if not content: | 99 if not content: |
| 96 logging.error('%s had empty content' % path) | 100 logging.error('%s had empty content' % path) |
| 97 | 101 |
| 98 headers.update({ | 102 headers.update({ |
| 99 'content-type': content_type, | 103 'content-type': content_type, |
| 100 'cache-control': 'max-age=300', | 104 'cache-control': 'max-age=300', |
| 101 }) | 105 }) |
| 102 return Response.Ok(content, headers=headers) | 106 return Response.Ok(content, headers=headers) |
| OLD | NEW |