The python backend is defined in handle_req.py
and requests are passed from
nginx via uwsgi.
Cookies and http authorization are forward directly to the CouchDB server. For
GET
and HEAD
requests, the backend checks to see if it can perform the
command on the associated document and returns the appropriate error code if
not. For PUT
and DELETE
requests, the backend relies on the fact that an
update function is available on the CouchDB database at the endpoint:
[db]/_design/nedm_default/_update/attachment/[doc_id]
This function is part of the nEDM-Interface and looks like:
Note that on a change (e.g. PUT
or DELETE
) a field is added or removed from
the field external_docs
on the document. The resulting document will be run
through the appropriate validate
functions,
which will check to see if the change is allowed.
When a request comes in to add or delete a file, the process looks like the following:
On PUT
:
where ‘populate entry’ adds the fields:
to doc.external_docs
.
A delete is similar, except the fields are removed. If it fails at any point, the appropriate HTTP code is returned.
If normal files are requested (e.g. without downsample requests), then these
are served directly by nginx using the X-Accel-Redirect
header (see e.g.
here).
This is generally the most efficient way to serve files statically from disk.
Requests with downsample
are processed by the python backend and served from
it (not directly from nginx).