| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 if path_with_channel.endswith('/'): | 51 if path_with_channel.endswith('/'): |
| 52 return Response.Redirect(path_with_channel + 'index.html') | 52 return Response.Redirect(path_with_channel + 'index.html') |
| 53 | 53 |
| 54 channel, path = BranchUtility.SplitChannelNameFromPath(path_with_channel) | 54 channel, path = BranchUtility.SplitChannelNameFromPath(path_with_channel) |
| 55 | 55 |
| 56 if channel == _DEFAULT_CHANNEL: | 56 if channel == _DEFAULT_CHANNEL: |
| 57 return Response.Redirect('/%s' % path) | 57 return Response.Redirect('/%s' % path) |
| 58 | 58 |
| 59 if channel is None: | 59 if channel is None: |
| 60 channel = _DEFAULT_CHANNEL | 60 channel = _DEFAULT_CHANNEL |
| 61 static_path = '/static' |
| 62 else: |
| 63 static_path = '/%s/static' % channel |
| 61 | 64 |
| 62 # AppEngine instances should never need to call out to SVN. That should | 65 # AppEngine instances should never need to call out to SVN. That should |
| 63 # only ever be done by the cronjobs, which then write the result into | 66 # only ever be done by the cronjobs, which then write the result into |
| 64 # DataStore, which is as far as instances look. To enable this, crons can | 67 # DataStore, which is as far as instances look. To enable this, crons can |
| 65 # pass a custom (presumably online) ServerInstance into Get(). | 68 # pass a custom (presumably online) ServerInstance into Get(). |
| 66 # | 69 # |
| 67 # Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but | 70 # Why? SVN is slow and a bit flaky. Cronjobs failing is annoying but |
| 68 # temporary. Instances failing affects users, and is really bad. | 71 # temporary. Instances failing affects users, and is really bad. |
| 69 # | 72 # |
| 70 # Anyway - to enforce this, we actually don't give instances access to SVN. | 73 # Anyway - to enforce this, we actually don't give instances access to SVN. |
| 71 # If anything is missing from datastore, it'll be a 404. If the cronjobs | 74 # If anything is missing from datastore, it'll be a 404. If the cronjobs |
| 72 # don't manage to catch everything - uhoh. On the other hand, we'll figure | 75 # don't manage to catch everything - uhoh. On the other hand, we'll figure |
| 73 # it out pretty soon, and it also means that legitimate 404s are caught | 76 # it out pretty soon, and it also means that legitimate 404s are caught |
| 74 # before a round trip to SVN. | 77 # before a round trip to SVN. |
| 75 if server_instance is None: | 78 if server_instance is None: |
| 76 # The ALWAYS_ONLINE thing is for tests and preview.py that shouldn't need | 79 # The ALWAYS_ONLINE thing is for tests and preview.py that shouldn't need |
| 77 # to run the cron before rendering things. | 80 # to run the cron before rendering things. |
| 78 constructor = (ServerInstance.CreateOnline if _ALWAYS_ONLINE else | 81 constructor = (ServerInstance.CreateOnline if _ALWAYS_ONLINE else |
| 79 ServerInstance.GetOrCreateOffline) | 82 ServerInstance.GetOrCreateOffline) |
| 80 server_instance = constructor(channel) | 83 server_instance = constructor(channel, static_path) |
| 81 | 84 |
| 82 canonical_path = server_instance.path_canonicalizer.Canonicalize(path) | 85 canonical_path = server_instance.path_canonicalizer.Canonicalize(path) |
| 83 if path != canonical_path: | 86 if path != canonical_path: |
| 84 return Response.Redirect(canonical_path if channel is None else | 87 return Response.Redirect(canonical_path if channel is None else |
| 85 '%s/%s' % (channel, canonical_path)) | 88 '%s/%s' % (channel, canonical_path)) |
| 86 | 89 |
| 87 templates = server_instance.template_data_source_factory.Create( | 90 templates = server_instance.template_data_source_factory.Create( |
| 88 self._request, path) | 91 self._request, path) |
| 89 | 92 |
| 90 content = None | 93 content = None |
| (...skipping 28 matching lines...) Expand all Loading... |
| 119 return Response.NotFound(templates.Render('404'), headers=headers) | 122 return Response.NotFound(templates.Render('404'), headers=headers) |
| 120 | 123 |
| 121 if not content: | 124 if not content: |
| 122 logging.error('%s had empty content' % path) | 125 logging.error('%s had empty content' % path) |
| 123 | 126 |
| 124 headers.update({ | 127 headers.update({ |
| 125 'content-type': content_type, | 128 'content-type': content_type, |
| 126 'cache-control': 'max-age=300', | 129 'cache-control': 'max-age=300', |
| 127 }) | 130 }) |
| 128 return Response.Ok(content, headers=headers) | 131 return Response.Ok(content, headers=headers) |
| OLD | NEW |