diff options
| author | Tom Christie | 2012-01-11 14:37:25 +0000 |
|---|---|---|
| committer | Tom Christie | 2012-01-11 14:37:25 +0000 |
| commit | b522cc8e5139963acd5083e8a822345a48b59a80 (patch) | |
| tree | 4aca8ee2e4d6b27415a229c8cf14315742980847 /djangorestframework/views.py | |
| parent | 0cfe2acdef7faf25d74af6593bc99019bebb3d8a (diff) | |
| parent | 35ba2fc65b0cd1431e29b354e9c7e9bbfa36c147 (diff) | |
| download | django-rest-framework-b522cc8e5139963acd5083e8a822345a48b59a80.tar.bz2 | |
Merge https://github.com/dzen/django-rest-framework
Diffstat (limited to 'djangorestframework/views.py')
| -rw-r--r-- | djangorestframework/views.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py index 4606e50b..9241c993 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -154,19 +154,8 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): except ErrorResponse, exc: response = exc.response - # Always add these headers. - # - # TODO - this isn't actually the correct way to set the vary header, - # also it's currently sub-optimal for HTTP caching - need to sort that out. - response.headers['Allow'] = ', '.join(self.allowed_methods) - response.headers['Vary'] = 'Authenticate, Accept' - - # merge with headers possibly set at some point in the view - response.headers.update(self.headers) - set_script_prefix(orig_prefix) - - return self.render(response) + return self.final(request, response, *args, **kwargs) def options(self, request, *args, **kwargs): response_obj = { @@ -183,6 +172,19 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): response_obj['fields'] = field_name_types return response_obj + def final(self, request, response, *args, **kargs): + """ + Hook for any code that needs to run after everything else in the view. + """ + # Always add these headers. + response.headers['Allow'] = ', '.join(self.allowed_methods) + # sample to allow caching using Vary http header + response.headers['Vary'] = 'Authenticate, Accept' + + # merge with headers possibly set at some point in the view + response.headers.update(self.headers) + return self.render(response) + class ModelView(View): """ |
