summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-03-09 19:52:54 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-03-09 19:52:54 +0000
commit610064aea6eb707fe3b6a68f7c93005ceac0a2ec (patch)
tree432a31e5c0561e10f9b1e4973c2741c5c777c1f1 /src
parentdd79e85bc9e4849df904498ca25ec56304440b5f (diff)
merge design doc resource branch. breaking changes to _view query paths.
closes COUCHDB-280 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@751813 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_db.hrl3
-rw-r--r--src/couchdb/couch_httpd.erl16
-rw-r--r--src/couchdb/couch_httpd_db.erl12
-rw-r--r--src/couchdb/couch_httpd_show.erl10
-rw-r--r--src/couchdb/couch_httpd_view.erl10
5 files changed, 37 insertions, 14 deletions
diff --git a/src/couchdb/couch_db.hrl b/src/couchdb/couch_db.hrl
index aa97a19c..026afe14 100644
--- a/src/couchdb/couch_db.hrl
+++ b/src/couchdb/couch_db.hrl
@@ -61,7 +61,8 @@
path_parts,
db_url_handlers,
user_ctx,
- req_body = undefined
+ req_body = undefined,
+ design_url_handlers
}).
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 44ae0bb1..48ff403b 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -13,7 +13,7 @@
-module(couch_httpd).
-include("couch_db.hrl").
--export([start_link/0, stop/0, handle_request/3]).
+-export([start_link/0, stop/0, handle_request/4]).
-export([header_value/2,header_value/3,qs_value/2,qs_value/3,qs/1,path/1,absolute_uri/2]).
-export([verify_is_server_admin/1,unquote/1,quote/1,recv/2,recv_chunked/4]).
@@ -44,11 +44,18 @@ start_link() ->
fun({UrlKey, SpecStr}) ->
{?l2b(UrlKey), make_arity_2_fun(SpecStr)}
end, couch_config:get("httpd_db_handlers")),
+
+ DesignUrlHandlersList = lists:map(
+ fun({UrlKey, SpecStr}) ->
+ {?l2b(UrlKey), make_arity_2_fun(SpecStr)}
+ end, couch_config:get("httpd_design_handlers")),
+
UrlHandlers = dict:from_list(UrlHandlersList),
DbUrlHandlers = dict:from_list(DbUrlHandlersList),
+ DesignUrlHandlers = dict:from_list(DesignUrlHandlersList),
Loop = fun(Req)->
apply(?MODULE, handle_request,
- [Req, UrlHandlers, DbUrlHandlers])
+ [Req, UrlHandlers, DbUrlHandlers, DesignUrlHandlers])
end,
% and off we go
@@ -101,7 +108,7 @@ stop() ->
mochiweb_http:stop(?MODULE).
-handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
+handle_request(MochiReq, UrlHandlers, DbUrlHandlers, DesignUrlHandlers) ->
statistics(runtime), % prepare request_time counter, see end of function
AuthenticationFun = make_arity_1_fun(
couch_config:get("httpd", "authentication_handler")),
@@ -147,7 +154,8 @@ handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
method = Method,
path_parts = [list_to_binary(couch_httpd:unquote(Part))
|| Part <- string:tokens(Path, "/")],
- db_url_handlers = DbUrlHandlers
+ db_url_handlers = DbUrlHandlers,
+ design_url_handlers = DesignUrlHandlers
},
DefaultFun = fun couch_httpd_db:handle_request/1,
HandlerFun = couch_util:dict_find(HandlerKey, UrlHandlers, DefaultFun),
diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl
index 005e32d1..75022cd3 100644
--- a/src/couchdb/couch_httpd_db.erl
+++ b/src/couchdb/couch_httpd_db.erl
@@ -13,7 +13,7 @@
-module(couch_httpd_db).
-include("couch_db.hrl").
--export([handle_request/1, db_req/2, couch_doc_open/4]).
+-export([handle_request/1, handle_design_req/2, db_req/2, couch_doc_open/4]).
-import(couch_httpd,
[send_json/2,send_json/3,send_json/4,send_method_not_allowed/2,
@@ -41,6 +41,16 @@ handle_request(#httpd{path_parts=[DbName|RestParts],method=Method,
do_db_req(Req, Handler)
end.
+handle_design_req(#httpd{
+ path_parts=[_DbName,_Design,_DesName, <<"_",_/binary>> = Action | _Rest],
+ design_url_handlers = DesignUrlHandlers
+ }=Req, Db) ->
+ Handler = couch_util:dict_find(Action, DesignUrlHandlers, fun db_req/2),
+ Handler(Req, Db);
+
+handle_design_req(Req, Db) ->
+ db_req(Req, Db).
+
create_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) ->
ok = couch_httpd:verify_is_server_admin(Req),
case couch_server:create(DbName, [{user_ctx, UserCtx}]) of
diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl
index 5a03d9de..7b6f2832 100644
--- a/src/couchdb/couch_httpd_show.erl
+++ b/src/couchdb/couch_httpd_show.erl
@@ -24,7 +24,7 @@
handle_doc_show_req(#httpd{
method='GET',
- path_parts=[_, _, DesignName, ShowName, DocId]
+ path_parts=[_DbName, _Design, DesignName, _Show, ShowName, DocId]
}=Req, Db) ->
DesignId = <<"_design/", DesignName/binary>>,
#doc{body={Props}} = couch_httpd_db:couch_doc_open(Db, DesignId, [], []),
@@ -39,7 +39,7 @@ handle_doc_show_req(#httpd{
handle_doc_show_req(#httpd{
method='GET',
- path_parts=[_, _, DesignName, ShowName]
+ path_parts=[_DbName, _Design, DesignName, _Show, ShowName]
}=Req, Db) ->
DesignId = <<"_design/", DesignName/binary>>,
#doc{body={Props}} = couch_httpd_db:couch_doc_open(Db, DesignId, [], []),
@@ -53,7 +53,8 @@ handle_doc_show_req(#httpd{method='GET'}=Req, _Db) ->
handle_doc_show_req(Req, _Db) ->
send_method_not_allowed(Req, "GET,HEAD").
-handle_view_list_req(#httpd{method='GET',path_parts=[_, _, DesignName, ListName, ViewName]}=Req, Db) ->
+handle_view_list_req(#httpd{method='GET',
+ path_parts=[_DbName, _Design, DesignName, _List, ListName, ViewName]}=Req, Db) ->
DesignId = <<"_design/", DesignName/binary>>,
#doc{body={Props}} = couch_httpd_db:couch_doc_open(Db, DesignId, [], []),
Lang = proplists:get_value(<<"language">>, Props, <<"javascript">>),
@@ -63,7 +64,8 @@ handle_view_list_req(#httpd{method='GET',path_parts=[_, _, DesignName, ListName,
handle_view_list_req(#httpd{method='GET'}=Req, _Db) ->
send_error(Req, 404, <<"list_error">>, <<"Invalid path.">>);
-handle_view_list_req(#httpd{method='POST',path_parts=[_, _, DesignName, ListName, ViewName]}=Req, Db) ->
+handle_view_list_req(#httpd{method='POST',
+ path_parts=[_DbName, _Design, DesignName, _List, ListName, ViewName]}=Req, Db) ->
DesignId = <<"_design/", DesignName/binary>>,
#doc{body={Props}} = couch_httpd_db:couch_doc_open(Db, DesignId, [], []),
Lang = proplists:get_value(<<"language">>, Props, <<"javascript">>),
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index 6b9befe1..322cf945 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -49,13 +49,15 @@ design_doc_view(Req, Db, Id, ViewName, Keys) ->
couch_stats_collector:increment({httpd, view_reads}),
Result.
-handle_view_req(#httpd{method='GET',path_parts=[_,_, Id, ViewName]}=Req, Db) ->
- design_doc_view(Req, Db, Id, ViewName, nil);
+handle_view_req(#httpd{method='GET',
+ path_parts=[_Db, _Design, DName, _View, ViewName]}=Req, Db) ->
+ design_doc_view(Req, Db, DName, ViewName, nil);
-handle_view_req(#httpd{method='POST',path_parts=[_,_, Id, ViewName]}=Req, Db) ->
+handle_view_req(#httpd{method='POST',
+ path_parts=[_Db, _Design, DName, _View, ViewName]}=Req, Db) ->
{Props} = couch_httpd:json_body(Req),
Keys = proplists:get_value(<<"keys">>, Props, nil),
- design_doc_view(Req, Db, Id, ViewName, Keys);
+ design_doc_view(Req, Db, DName, ViewName, Keys);
handle_view_req(Req, _Db) ->
send_method_not_allowed(Req, "GET,POST,HEAD").