couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chewbra...@apache.org
Subject [06/41] chttpd commit: updated refs/heads/2080-port-cors to e2c2bd7
Date Tue, 02 Jun 2015 19:30:56 GMT
Add _local_docs and _design_docs handlers

COUCHDB-1145


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/23477c63
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/23477c63
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/23477c63

Branch: refs/heads/2080-port-cors
Commit: 23477c63d62c8501037c7ea53e6f454e98c82bd3
Parents: b44515f
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Dec 18 13:20:51 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Thu Dec 18 13:20:51 2014 -0800

----------------------------------------------------------------------
 src/chttpd_db.erl | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/23477c63/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 24eb78c..bd54a8a 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -437,6 +437,54 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_all_docs">>]}=Req,
Db) ->
 db_req(#httpd{path_parts=[_,<<"_all_docs">>]}=Req, _Db) ->
     send_method_not_allowed(Req, "GET,HEAD,POST");
 
+db_req(#httpd{method='GET',path_parts=[_,<<"_local_docs">>]}=Req, Db) ->
+    case chttpd:qs_json_value(Req, "keys", nil) of
+    Keys when is_list(Keys) ->
+        all_docs_view(Req, Db, Keys, <<"_local">>);
+    nil ->
+        all_docs_view(Req, Db, undefined, <<"_local">>);
+    _ ->
+        throw({bad_request, "`keys` parameter must be an array."})
+    end;
+
+db_req(#httpd{method='POST',path_parts=[_,<<"_local_docs">>]}=Req, Db) ->
+    {Fields} = chttpd:json_body_obj(Req),
+    case couch_util:get_value(<<"keys">>, Fields, nil) of
+    Keys when is_list(Keys) ->
+        all_docs_view(Req, Db, Keys, <<"_local">>);
+    nil ->
+        all_docs_view(Req, Db, undefined, <<"_local">>);
+    _ ->
+        throw({bad_request, "`keys` body member must be an array."})
+    end;
+
+db_req(#httpd{path_parts=[_,<<"_local_docs">>]}=Req, _Db) ->
+    send_method_not_allowed(Req, "GET,HEAD,POST");
+
+db_req(#httpd{method='GET',path_parts=[_,<<"_design_docs">>]}=Req, Db) ->
+    case chttpd:qs_json_value(Req, "keys", nil) of
+    Keys when is_list(Keys) ->
+        all_docs_view(Req, Db, Keys, <<"_design">>);
+    nil ->
+        all_docs_view(Req, Db, undefined, <<"_design">>);
+    _ ->
+        throw({bad_request, "`keys` parameter must be an array."})
+    end;
+
+db_req(#httpd{method='POST',path_parts=[_,<<"_design_docs">>]}=Req, Db) ->
+    {Fields} = chttpd:json_body_obj(Req),
+    case couch_util:get_value(<<"keys">>, Fields, nil) of
+    Keys when is_list(Keys) ->
+        all_docs_view(Req, Db, Keys, <<"_design">>);
+    nil ->
+        all_docs_view(Req, Db, undefined, <<"_design">>);
+    _ ->
+        throw({bad_request, "`keys` body member must be an array."})
+    end;
+
+db_req(#httpd{path_parts=[_,<<"_design_docs">>]}=Req, _Db) ->
+    send_method_not_allowed(Req, "GET,HEAD,POST");
+
 db_req(#httpd{method='POST',path_parts=[_,<<"_missing_revs">>]}=Req, Db) ->
     {JsonDocIdRevs} = chttpd:json_body_obj(Req),
     {ok, Results} = fabric:get_missing_revs(Db, JsonDocIdRevs),
@@ -533,11 +581,14 @@ db_req(#httpd{path_parts=[_, DocId | FileNameParts]}=Req, Db) ->
     db_attachment_req(Req, Db, DocId, FileNameParts).
 
 all_docs_view(Req, Db, Keys) ->
+    all_docs_view(Req, Db, Keys, undefined).
+all_docs_view(Req, Db, Keys, NS) ->
     Args0 = couch_mrview_http:parse_params(Req, Keys),
+    Args1 = set_namespace(NS, Args0),
     ETagFun = fun(Sig, Acc0) ->
         couch_mrview_http:check_view_etag(Sig, Acc0, Req)
     end,
-    Args = Args0#mrargs{preflight_fun=ETagFun},
+    Args = Args1#mrargs{preflight_fun=ETagFun},
     Options = [{user_ctx, Req#httpd.user_ctx}],
     {ok, Resp} = couch_httpd:etag_maybe(Req, fun() ->
         VAcc0 = #vacc{db=Db, req=Req},
@@ -1446,6 +1497,9 @@ put_security(#httpd{user_ctx=Ctx}=Req, Db, FetchRev) ->
             end
     end.
 
+set_namespace(NS, #mrargs{extra = Extra} = Args) ->
+    Args#mrargs{extra = [{namespace, NS} | Extra]}.
+
 -ifdef(TEST).
 -include_lib("eunit/include/eunit.hrl").
 


Mime
View raw message