summaryrefslogtreecommitdiff
path: root/src/mango/src/mango_httpd.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mango/src/mango_httpd.erl')
-rw-r--r--src/mango/src/mango_httpd.erl23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/mango/src/mango_httpd.erl b/src/mango/src/mango_httpd.erl
index 2e8777135..d73ec6cb5 100644
--- a/src/mango/src/mango_httpd.erl
+++ b/src/mango/src/mango_httpd.erl
@@ -170,7 +170,8 @@ handle_index_req(#httpd{path_parts=[_, _, _DDocId0, _Type, _Name]}=Req, _Db) ->
handle_explain_req(#httpd{method='POST'}=Req, Db) ->
chttpd:validate_ctype(Req, "application/json"),
- {ok, Opts0} = mango_opts:validate_find(chttpd:json_body_obj(Req)),
+ Body = maybe_set_partition(Req),
+ {ok, Opts0} = mango_opts:validate_find(Body),
{value, {selector, Sel}, Opts} = lists:keytake(selector, 1, Opts0),
Resp = mango_crud:explain(Db, Sel, Opts),
chttpd:send_json(Req, Resp);
@@ -181,7 +182,8 @@ handle_explain_req(Req, _Db) ->
handle_find_req(#httpd{method='POST'}=Req, Db) ->
chttpd:validate_ctype(Req, "application/json"),
- {ok, Opts0} = mango_opts:validate_find(chttpd:json_body_obj(Req)),
+ Body = maybe_set_partition(Req),
+ {ok, Opts0} = mango_opts:validate_find(Body),
{value, {selector, Sel}, Opts} = lists:keytake(selector, 1, Opts0),
{ok, Resp0} = start_find_resp(Req),
{ok, AccOut} = run_find(Resp0, Db, Sel, Opts),
@@ -224,6 +226,23 @@ get_idx_del_opts(Req) ->
end.
+maybe_set_partition(Req) ->
+ {Props} = chttpd:json_body_obj(Req),
+ case chttpd:qs_value(Req, "partition", undefined) of
+ undefined ->
+ {Props};
+ Partition ->
+ case couch_util:get_value(<<"partition">>, Props) of
+ undefined ->
+ {[{<<"partition">>, ?l2b(Partition)} | Props]};
+ Partition ->
+ {Props};
+ OtherPartition ->
+ ?MANGO_ERROR({bad_partition, OtherPartition})
+ end
+ end.
+
+
convert_to_design_id(DDocId) ->
case DDocId of
<<"_design/", _/binary>> -> DDocId;