diff options
| author | Tom Christie | 2011-06-15 14:41:09 +0100 |
|---|---|---|
| committer | Tom Christie | 2011-06-15 14:41:09 +0100 |
| commit | 1cb84cd4e82880caea645ebd99a947cead3096b9 (patch) | |
| tree | 5ae955f4a7ef5cd9754f2b5c11caecdedcad1f10 /djangorestframework/views.py | |
| parent | ff6e78323f88fd58b1de5b02e2440c2fc24c9c8b (diff) | |
| parent | 49a2817eb5ccf5f176ff5366d69df3a307dfcda2 (diff) | |
| download | django-rest-framework-1cb84cd4e82880caea645ebd99a947cead3096b9.tar.bz2 | |
Merge throttling and fix up a coupla things
Diffstat (limited to 'djangorestframework/views.py')
| -rw-r--r-- | djangorestframework/views.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py index 49d722c5..18d064e1 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -64,7 +64,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): """ permissions = ( permissions.FullAnonAccess, ) - + @classmethod def as_view(cls, **initkwargs): """ @@ -101,6 +101,14 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): """ pass + + def add_header(self, field, value): + """ + Add *field* and *value* to the :attr:`headers` attribute of the :class:`View` class. + """ + self.headers[field] = value + + # Note: session based authentication is explicitly CSRF validated, # all other authentication is CSRF exempt. @csrf_exempt @@ -108,6 +116,7 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): self.request = request self.args = args self.kwargs = kwargs + self.headers = {} # Calls to 'reverse' will not be fully qualified unless we set the scheme/host/port here. prefix = '%s://%s' % (request.is_secure() and 'https' or 'http', request.get_host()) @@ -149,9 +158,12 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): # also it's currently sub-obtimal 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) + + return self.render(response) - return self.render(response) - class ModelView(View): """A RESTful view that maps to a model in the database.""" |
