diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-12-22 19:46:12 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-12-22 19:46:12 +0000 |
commit | 214b6f9b9d4c9cd9182d2ce56b9a5ffd9f6d0864 (patch) | |
tree | 766bbd1fe6c3d2819303debd8a1b75cfd8805e6f /src | |
parent | 0067f2e76ddcb1143d17de73fee878f68286aaae (diff) |
Merged revision 1052047 from trunk:
Allow a multipart/mixed document GET to send the attachments in encoded (compressed) form
Currently this API is not used internally but it's a very important one for the new replicator.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1052048 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/couchdb/couch_httpd_db.erl | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index c11d2aef..532b939c 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -747,24 +747,30 @@ send_doc_efficiently(#httpd{mochi_req = MochiReq} = Req, send_json(Req, 200, Headers, couch_doc:to_json_obj(Doc, Options)) end. -send_docs_multipart(Req, Results, Options) -> +send_docs_multipart(Req, Results, Options1) -> OuterBoundary = couch_uuids:random(), InnerBoundary = couch_uuids:random(), + {Options, CompressedAtts} = + case couch_httpd:header_value(Req, "X-CouchDB-Send-Encoded-Atts") of + "true" -> + {[attachments, follows, att_encoding_info | Options1], true}; + _ -> + {[attachments, follows | Options1], false} + end, CType = {"Content-Type", "multipart/mixed; boundary=\"" ++ ?b2l(OuterBoundary) ++ "\""}, {ok, Resp} = start_chunked_response(Req, 200, [CType]), couch_httpd:send_chunk(Resp, <<"--", OuterBoundary/binary>>), lists:foreach( fun({ok, #doc{atts=Atts}=Doc}) -> - JsonBytes = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, - [attachments,follows|Options])), + JsonBytes = ?JSON_ENCODE(couch_doc:to_json_obj(Doc, Options)), {ContentType, _Len} = couch_doc:len_doc_to_multi_part_stream( - InnerBoundary, JsonBytes, Atts, false), + InnerBoundary, JsonBytes, Atts, CompressedAtts), couch_httpd:send_chunk(Resp, <<"\r\nContent-Type: ", ContentType/binary, "\r\n\r\n">>), couch_doc:doc_to_multi_part_stream(InnerBoundary, JsonBytes, Atts, fun(Data) -> couch_httpd:send_chunk(Resp, Data) - end, false), + end, CompressedAtts), couch_httpd:send_chunk(Resp, <<"\r\n--", OuterBoundary/binary>>); ({{not_found, missing}, RevId}) -> RevStr = couch_doc:rev_to_str(RevId), |