| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 content_provider, serve_from, path = ( | 84 content_provider, serve_from, path = ( |
| 85 server_instance.content_providers.GetByServeFrom(request_path)) | 85 server_instance.content_providers.GetByServeFrom(request_path)) |
| 86 assert content_provider, 'No ContentProvider found for %s' % path | 86 assert content_provider, 'No ContentProvider found for %s' % path |
| 87 | 87 |
| 88 redirect = Redirector( | 88 redirect = Redirector( |
| 89 server_instance.compiled_fs_factory, | 89 server_instance.compiled_fs_factory, |
| 90 content_provider.file_system).Redirect(self._request.host, path) | 90 content_provider.file_system).Redirect(self._request.host, path) |
| 91 if redirect is not None: | 91 if redirect is not None: |
| 92 # Absolute redirects stay absolute, relative redirects are relative to | 92 # Absolute redirects stay absolute, relative redirects are relative to |
| 93 # |serve_from|; all redirects eventually need to be *served* as absolute. | 93 # |serve_from|; all redirects eventually need to be *served* as absolute. |
| 94 if not redirect.startswith('/'): | 94 if not redirect.startswith(('/', 'http://', 'https://')): |
| 95 redirect = '/' + posixpath.join(serve_from, redirect) | 95 redirect = '/' + posixpath.join(serve_from, redirect) |
| 96 return Response.Redirect(redirect, permanent=False) | 96 return Response.Redirect(redirect, permanent=False) |
| 97 | 97 |
| 98 canonical_path = content_provider.GetCanonicalPath(path) | 98 canonical_path = content_provider.GetCanonicalPath(path) |
| 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 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if etag is None: | 142 if etag is None: |
| 143 # 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 |
| 144 # 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 |
| 145 # 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. |
| 146 etag = '"%s"' % hashlib.md5(content).hexdigest() | 146 etag = '"%s"' % hashlib.md5(content).hexdigest() |
| 147 | 147 |
| 148 headers = _MakeHeaders(content_type, etag=etag) | 148 headers = _MakeHeaders(content_type, etag=etag) |
| 149 if etag == self._request.headers.get('If-None-Match'): | 149 if etag == self._request.headers.get('If-None-Match'): |
| 150 return Response.NotModified('Not Modified', headers=headers) | 150 return Response.NotModified('Not Modified', headers=headers) |
| 151 return Response.Ok(content, headers=headers) | 151 return Response.Ok(content, headers=headers) |
| OLD | NEW |