| 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 import hashlib | 5 import hashlib |
| 6 import logging | 6 import logging |
| 7 import posixpath | 7 import posixpath |
| 8 import traceback | 8 import traceback |
| 9 | 9 |
| 10 from branch_utility import BranchUtility | 10 from branch_utility import BranchUtility |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 if canonical_path != path: | 99 if canonical_path != path: |
| 100 redirect_path = posixpath.join(serve_from, canonical_path) | 100 redirect_path = posixpath.join(serve_from, canonical_path) |
| 101 return Response.Redirect('/' + redirect_path, permanent=False) | 101 return Response.Redirect('/' + redirect_path, permanent=False) |
| 102 | 102 |
| 103 if request_path.endswith('/'): | 103 if request_path.endswith('/'): |
| 104 # Directory request hasn't been redirected by now. Default behaviour is | 104 # Directory request hasn't been redirected by now. Default behaviour is |
| 105 # to redirect as though it were a file. | 105 # to redirect as though it were a file. |
| 106 return Response.Redirect('/' + request_path.rstrip('/'), | 106 return Response.Redirect('/' + request_path.rstrip('/'), |
| 107 permanent=False) | 107 permanent=False) |
| 108 | 108 |
| 109 if not path: | |
| 110 # Empty-path request hasn't been redirected by now. It doesn't exist. | |
| 111 raise FileNotFoundError('Empty path') | |
| 112 | |
| 113 content_and_type = content_provider.GetContentAndType(path).Get() | 109 content_and_type = content_provider.GetContentAndType(path).Get() |
| 114 if not content_and_type.content: | 110 if not content_and_type.content: |
| 115 logging.error('%s had empty content' % path) | 111 logging.error('%s had empty content' % path) |
| 116 | 112 |
| 117 content = content_and_type.content | 113 content = content_and_type.content |
| 118 if isinstance(content, Handlebar): | 114 if isinstance(content, Handlebar): |
| 119 template_content, template_warnings = ( | 115 template_content, template_warnings = ( |
| 120 server_instance.template_renderer.Render(content, self._request)) | 116 server_instance.template_renderer.Render(content, self._request)) |
| 121 # HACK: the site verification file (google2ed...) doesn't have a title. | 117 # HACK: the site verification file (google2ed...) doesn't have a title. |
| 122 content, doc_warnings = server_instance.document_renderer.Render( | 118 content, doc_warnings = server_instance.document_renderer.Render( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 146 if etag is None: | 142 if etag is None: |
| 147 # Note: we're using md5 as a convenient and fast-enough way to identify | 143 # Note: we're using md5 as a convenient and fast-enough way to identify |
| 148 # content. It's not intended to be cryptographic in any way, and this | 144 # content. It's not intended to be cryptographic in any way, and this |
| 149 # is *not* what etags is for. That's what SSL is for, this is unrelated. | 145 # is *not* what etags is for. That's what SSL is for, this is unrelated. |
| 150 etag = '"%s"' % hashlib.md5(content).hexdigest() | 146 etag = '"%s"' % hashlib.md5(content).hexdigest() |
| 151 | 147 |
| 152 headers = _MakeHeaders(content_type, etag=etag) | 148 headers = _MakeHeaders(content_type, etag=etag) |
| 153 if etag == self._request.headers.get('If-None-Match'): | 149 if etag == self._request.headers.get('If-None-Match'): |
| 154 return Response.NotModified('Not Modified', headers=headers) | 150 return Response.NotModified('Not Modified', headers=headers) |
| 155 return Response.Ok(content, headers=headers) | 151 return Response.Ok(content, headers=headers) |
| OLD | NEW |