nickva commented on a change in pull request #1195: Add support for bulk get
with Accept:"multipart/mixed" or "multipart/related"
URL: https://github.com/apache/couchdb/pull/1195#discussion_r232427519
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -481,18 +482,62 @@ db_req(#httpd{method='POST', path_parts=[_,
<<"_bulk_get">>]}=Req, Db) ->
} = bulk_get_parse_doc_query(Req),
Options = [{user_ctx, Req#httpd.user_ctx} | Options0],
- {ok, Resp} = start_json_response(Req, 200),
- send_chunk(Resp, <<"{\"results\": [">>),
-
- lists:foldl(fun(Doc, Sep) ->
- {DocId, Results, Options1} = bulk_get_open_doc_revs(Db, Doc,
- Options),
- bulk_get_send_docs_json(Resp, DocId, Results, Options1, Sep),
- <<",">>
- end, <<"">>, Docs),
-
- send_chunk(Resp, <<"]}">>),
- end_json_response(Resp)
+ % Decide whether to use multipart response or application/json
+ AcceptMixedMp = MochiReq:accepts_content_type("multipart/mixed"),
+ AcceptRelatedMp =
MochiReq:accepts_content_type("multipart/related"),
+ AcceptMp = AcceptMixedMp orelse AcceptRelatedMp,
Review comment:
Sorry one more thing I realized. I think this logic would make multipart
response become the default if there is no accept header or it accepts `*/*`.
In general the semantics would be correct, but given that this is a new
behavior, it would be better if in such cases we returned json, and only if
json is not accepted but multipart is then we send multipart.
So I think we'd want something like:
```
AcceptJson = MochiReq:accepts_content_type("application/json"),
...
SendMp = not AcceptJson andalso (AcceptMixedMp orelse AcceptRelatedMp)
case SendMp of ...
```
So we are saying we only send mp if json wasn't requested (either because of
a `*/*` accept header or explicitly) and one of the mp flavors was. Otherwise
we send json as before.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services