AlexanderKaraberov opened a new pull request #1195: Add support for bulk get 
with Accept Content Type: "multipart/mixed", "multipart/related"
   ## Overview
   CouchDB currently has support for `_bulk_get` requests which are intended to 
improve performance of client pull replications, by allowing the client to 
request multiple documents in one request. But current implementation has some 
limitations namely: attachment bodies can only be encoded inline (base64) not 
as MIME multipart bodies. Another issue which was much more important in our 
case: current _bulk_get implementation in CouchDB is not compatible with the 
[Couchbase Lite 
1.4.x]( for 
iOS and Android because their `BulkDownloader` accepts [multipart/related 
 and not `application/json`. 
   This PR adds support for `multipart/related`/`multipart/mixed` _bulk_get 
response which is compatible with [Couchbase Lite/Sync 
Gateway]( Code is 
pretty much based on the [rcouch]( implementation 
with some changes to make it compatible with current CouchDB 2 architecture and 
also doesn't use any external libraries. 
   Logic is pretty simple: depending on the `case 
MochiReq:accepts_content_type("multipart/mixed")` check I pick either a default 
CouchDB's _bulk_get implementation or a multipart one. I specifically added a 
`send_doc_multipart` function so that not to break an existing 
`send_docs_multipart` one which wasn't compatible with the logic.
   We already tested this with some of the big production CouchDB databases and 
speedup was very noticeable. I think this feature will be very useful because 
there are a lot of Couchbase Lite users who can't benefit from the _bulk_get 
because of `application/json` only response. Plus this is a completely additive 
change which doesn't break/change existing functionality. Test suite is based 
on the `chttpd_db_bulk_get_test`. If some of the tests are missing or there are 
some issues with the implementation - feel free to point and I will fix them.
   ## Testing recommendations
   For testing create a `db1`, put some docs there: 
   curl -u admin:rm -X PUT
   curl -u admin:rm -H "Content-Type: application/json" -X PUT -d '{"type":"a"}'
   curl -u admin:rm -H "Content-Type: application/json" -X PUT -d '{"type":"a"}'
   curl -u admin:rm -H "Content-Type: application/json" -X PUT -d '{"type":"b"}'
   Also add attachments for some of the docs (.png images or whatnot). After 
this you can execute similar curl command:
   curl -u "admin:rm" -X POST -H "Content-Type: application/json" -H "Accept: 
multipart/related" -H "X-Accept-Part-Encoding: gzip"  -o "response.json" -d 
'{"docs": [{"id":"doc1", "rev": "1-8d0539dc5c5fe98d4069d2d0b06d9fa6"},{"id": 
"doc2", "rev":"1-b59ac7ccf4c21b26f6a4e1d72c509f23"},{"id": "doc3", "rev": 
   Then in the response.json you can observe something similar to this:
   Content-Type: application/json
   X-Doc-Id: _design/briefcase
   X-Rev-Id: 3-9df87eb32d30ce1e01fe4ca121ac725e
   Content-Type: multipart/related; 
   Content-Type: application/json
   Content-Disposition: attachment; filename="IMG_0361.PNG"
   Content-Type: image/png
   Content-Length: 2466384
   IHDRe   ????aiCCPkCGColorSpaceDisplayP3(?c``RI,(?aa``??+)
   rwR???R`????b
   ????>@%0|????/???:%5?I?^??b????D?0?????d ??S??JS?l?????):
 8,?? ??30??????n???~??@?\;b??
 xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 5.4.0">
      <rdf:RDF xmlns:rdf="";>
         <rdf:Description rdf:about=""
   ?8?@IDATx????ga'~????~?o????#I+??I?Y??|?8??d0?9? &???c R
   This format is completely compatible with Couchbase Lite and also Sync 
Gateway implementation.
   ## Checklist
   - [ ] Code is written and works correctly;
   - [ ] Changes are covered by tests;
   - [ ] Documentation reflects the changes;

This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

Reply via email to