mozilla-services/cornice — Issue #8: handle 406 / Accept
Author: tarekziade
Created: 2011-12-05 21:34:19+00:00
State: open

``` python
# case 1 : static
@service.post(accept=('text/plain', 'application/json'))
def _service(request):
... if accept is in headers and not listed => 406...
# case 2: dynamic
def _get_accept(request):
""" docstring USED by the doc"""
...
return False, accepted
def _get_accept2(request):
""" docstring USED by the doc"""
request.validated['res'] = result
return True, None
@service.post(accept=_get_accept)
def _service(request):
... the decorator calls _get_accept, and returns a 406 if False
... get accept can prepare something to be used by the main function to return a response (response.validated['xxx'] = xxx)
request.response = request.validated['res']
```