diff options
| author | markotibold | 2011-06-13 20:42:37 +0200 |
|---|---|---|
| committer | markotibold | 2011-06-13 20:42:37 +0200 |
| commit | 437a062b6c389530b337e809c472fb470827aa78 (patch) | |
| tree | b563e86dfb0b490a9643714069379167586291d0 /djangorestframework/views.py | |
| parent | 1720c449045fba54f7af776f0259d6dc84e7e54b (diff) | |
| download | django-rest-framework-437a062b6c389530b337e809c472fb470827aa78.tar.bz2 | |
implemeneted #28
Diffstat (limited to 'djangorestframework/views.py')
| -rw-r--r-- | djangorestframework/views.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/djangorestframework/views.py b/djangorestframework/views.py index 6f2ab5b7..e38207ac 100644 --- a/djangorestframework/views.py +++ b/djangorestframework/views.py @@ -64,7 +64,11 @@ class View(ResourceMixin, RequestMixin, ResponseMixin, AuthMixin, DjangoView): """ permissions = ( permissions.FullAnonAccess, ) - + """ + Headers to be sent with response. + """ + headers = {} + @classmethod def as_view(cls, **initkwargs): """ @@ -101,6 +105,12 @@ 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 @@ -149,7 +159,10 @@ 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 by a Throttle class + response.headers = dict(response.headers.items() + self.headers.items()) + return self.render(response) |
