This patch adds the X-Couch-Id and X-Couch-Rev headers to responses, so that a custom default_handler can act on DB changes (e.g. create tasks).
We have a custom default_handler that creates Celery tasks via a Python process. It wraps the couch_httpd_d:handle_request/1 function, looks at the response, then creates some tasks. What it needs is the document Id and Rev for each PUT/POST/DELETE request, but those are not available from the Response on that level (the response body is sent to the socket inside the black box somewhere). The headers are available. So we decided to add the Id and Rev to the JSON responses and also the update function as X-Couch-Id and X-Couch-Rev. When using an update function, the rev is available though "X-Couch-Update-NewRev", so only the Id has been added.
We have a large amount of small databases (potentially thousands), so it is not practical to listen to changes on every DB.
If there is another recommendation to achieve this without patching, please suggest an alternative.
Document Id and Rev in response headers
You should be able to leverage the Etag response header instead of adding X-Couch-Rev, right?
Ah yes, that's true. Just need the ID then
Only return X-Couch-Id (rev is available in ETag)
Can you add a quick test for this? I’m happy to merge this then.
@bjnortier we are going to branch for 1.3.0 on Wednesday 5th. Are you able to add a test so we can get your patch in? Thanks for your contribution!
Will do asap
Test the X-Couch-Id header
Test added, I hope this conforms
Committed, thanks! :)
Can you close the PR for us? Thanks!