Chromium Code Reviews| 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 posixpath | 8 import posixpath |
| 9 import traceback | 9 import traceback |
| 10 from urlparse import urlsplit | 10 from urlparse import urlsplit |
| 11 | 11 |
| 12 from data_source_registry import CreateDataSources | 12 from data_source_registry import CreateDataSources |
| 13 from environment import IsPreviewServer | |
| 13 from file_system import FileNotFoundError | 14 from file_system import FileNotFoundError |
| 14 from redirector import Redirector | 15 from redirector import Redirector |
| 15 from servlet import Servlet, Response | 16 from servlet import Servlet, Response |
| 16 from third_party.handlebar import Handlebar | 17 from third_party.handlebar import Handlebar |
| 17 | 18 |
| 18 | 19 |
| 19 def _MakeHeaders(content_type): | 20 def _MakeHeaders(content_type): |
| 20 return { | 21 return { |
| 21 'X-Frame-Options': 'sameorigin', | 22 'X-Frame-Options': 'sameorigin', |
| 22 'Content-Type': content_type, | 23 'Content-Type': content_type, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 40 ''' Render the page for a request. | 41 ''' Render the page for a request. |
| 41 ''' | 42 ''' |
| 42 # TODO(kalman): a consistent path syntax (even a Path class?) so that we | 43 # TODO(kalman): a consistent path syntax (even a Path class?) so that we |
| 43 # can stop being so conservative with stripping and adding back the '/'s. | 44 # can stop being so conservative with stripping and adding back the '/'s. |
| 44 path = self._request.path.lstrip('/') | 45 path = self._request.path.lstrip('/') |
| 45 server_instance = self._delegate.CreateServerInstance() | 46 server_instance = self._delegate.CreateServerInstance() |
| 46 | 47 |
| 47 try: | 48 try: |
| 48 return self._GetSuccessResponse(path, server_instance) | 49 return self._GetSuccessResponse(path, server_instance) |
| 49 except FileNotFoundError: | 50 except FileNotFoundError: |
| 51 if IsPreviewServer(): | |
|
not at google - send to devlin
2013/11/16 21:54:41
helpful for debugging.
| |
| 52 logging.error(traceback.format_exc()) | |
| 50 # Maybe it didn't find the file because its canonical location is | 53 # Maybe it didn't find the file because its canonical location is |
| 51 # somewhere else; this is distinct from "redirects", which are typically | 54 # somewhere else; this is distinct from "redirects", which are typically |
| 52 # explicit. This is implicit. | 55 # explicit. This is implicit. |
| 53 canonical_result = server_instance.path_canonicalizer.Canonicalize(path) | 56 canonical_result = server_instance.path_canonicalizer.Canonicalize(path) |
| 54 redirect = canonical_result.path.lstrip('/') | 57 redirect = canonical_result.path.lstrip('/') |
| 55 if path != redirect: | 58 if path != redirect: |
| 56 return Response.Redirect('/' + redirect, | 59 return Response.Redirect('/' + redirect, |
| 57 permanent=canonical_result.permanent) | 60 permanent=canonical_result.permanent) |
| 58 | 61 |
| 59 # Not found for reals. Find the closest 404.html file and serve that; | 62 # Not found for reals. Find the closest 404.html file and serve that; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 content = content_and_type.content | 100 content = content_and_type.content |
| 98 if isinstance(content, Handlebar): | 101 if isinstance(content, Handlebar): |
| 99 content = server_instance.template_renderer.Render(content, self._request) | 102 content = server_instance.template_renderer.Render(content, self._request) |
| 100 | 103 |
| 101 content_type = content_and_type.content_type | 104 content_type = content_and_type.content_type |
| 102 if isinstance(content, unicode): | 105 if isinstance(content, unicode): |
| 103 content = content.encode('utf-8') | 106 content = content.encode('utf-8') |
| 104 content_type += '; charset=utf-8' | 107 content_type += '; charset=utf-8' |
| 105 | 108 |
| 106 return Response.Ok(content, headers=_MakeHeaders(content_type)) | 109 return Response.Ok(content, headers=_MakeHeaders(content_type)) |
| OLD | NEW |