summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_httpd_view.erl
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-07-10 00:59:36 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-07-10 00:59:36 +0000
commit9ccb235a2d58d6b7caf406952f18ca13d9889f3e (patch)
tree9a0f6ac06d91d6bd70aee5d6f921665423139653 /src/couchdb/couch_httpd_view.erl
parent2f18f60fea5a1de6a221c6124038399c47d42aa2 (diff)
Apply patch from Benoit Chesneau's COUCHDB-404
Restores 0.8-style /db/_view view urls and adds an option to render views and documents as other formats like: /db/docid?show=blog/post /db/_view/blog/posts?list=index We're retaining the longer _design/appname paths as well because that resource is valuable for reverse proxies and rewriters. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@792771 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_view.erl')
-rw-r--r--src/couchdb/couch_httpd_view.erl49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index 2028840c..0150582a 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -13,7 +13,7 @@
-module(couch_httpd_view).
-include("couch_db.hrl").
--export([handle_view_req/2,handle_temp_view_req/2]).
+-export([handle_view_req/2,handle_temp_view_req/2,handle_db_view_req/2]).
-export([get_stale_type/1, get_reduce_type/1, parse_view_params/3]).
-export([make_view_fold_fun/6, finish_view_fold/3, view_row_obj/3]).
@@ -73,6 +73,49 @@ handle_view_req(#httpd{method='POST',
handle_view_req(Req, _Db) ->
send_method_not_allowed(Req, "GET,POST,HEAD").
+handle_db_view_req(#httpd{method='GET',
+ path_parts=[_Db, _View, DName, ViewName]}=Req, Db) ->
+ QueryArgs = couch_httpd_view:parse_view_params(Req, nil, nil),
+ #view_query_args{
+ list = ListName
+ } = QueryArgs,
+ ?LOG_DEBUG("ici ~p", [ListName]),
+ case ListName of
+ nil -> couch_httpd_view:design_doc_view(Req, Db, DName, ViewName, nil);
+ _ ->
+ couch_httpd_show:handle_view_list(Req, DName, ListName, ViewName, Db, nil)
+ end;
+
+handle_db_view_req(#httpd{method='POST',
+ path_parts=[_Db, _View, DName, ViewName]}=Req, Db) ->
+ QueryArgs = couch_httpd_view:parse_view_params(Req, nil, nil),
+ #view_query_args{
+ list = ListName
+ } = QueryArgs,
+ case ListName of
+ nil ->
+ {Fields} = couch_httpd:json_body_obj(Req),
+ case proplists:get_value(<<"keys">>, Fields, nil) of
+ nil ->
+ Fmt = "POST to view ~p/~p in database ~p with no keys member.",
+ ?LOG_DEBUG(Fmt, [DName, ViewName, Db]),
+ couch_httpd_view:design_doc_view(Req, Db, DName, ViewName, nil);
+ Keys when is_list(Keys) ->
+ couch_httpd_view:design_doc_view(Req, Db, DName, ViewName, Keys);
+ _ ->
+ throw({bad_request, "`keys` member must be a array."})
+ end;
+ _ ->
+ ReqBody = couch_httpd:body(Req),
+ {Props2} = ?JSON_DECODE(ReqBody),
+ Keys = proplists:get_value(<<"keys">>, Props2, nil),
+ couch_httpd_show:handle_view_list(Req#httpd{req_body=ReqBody},
+ DName, ListName, ViewName, Db, Keys)
+ end;
+
+handle_db_view_req(Req, _Db) ->
+ send_method_not_allowed(Req, "GET,POST,HEAD").
+
handle_temp_view_req(#httpd{method='POST'}=Req, Db) ->
couch_stats_collector:increment({httpd, temporary_view_reads}),
{Props} = couch_httpd:json_body_obj(Req),
@@ -269,6 +312,8 @@ parse_view_param("reduce", Value) ->
[{reduce, parse_bool_param(Value)}];
parse_view_param("include_docs", Value) ->
[{include_docs, parse_bool_param(Value)}];
+parse_view_param("list", Value) ->
+ [{list, ?l2b(Value)}];
parse_view_param("callback", _) ->
[]; % Verified in the JSON response functions
parse_view_param(Key, Value) ->
@@ -298,6 +343,8 @@ validate_view_query(end_docid, Value, Args) ->
Args#view_query_args{end_docid=Value};
validate_view_query(limit, Value, Args) ->
Args#view_query_args{limit=Value};
+validate_view_query(list, Value, Args) ->
+ Args#view_query_args{list=Value};
validate_view_query(stale, _, Args) ->
Args;
validate_view_query(descending, true, Args) ->