From 7e0cc2163e9a00a617bef368b72d264e13417bca Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 5 Sep 2019 13:57:12 -0400 Subject: [PATCH 1/2] Remove old multi-query path Users should send requests with multiple queries to the new endpoint: /db/_design/{ddoc}/_view/{view}/queries Closes #2168 --- src/chttpd/src/chttpd_view.erl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl index 26107d7c524..42c3afdf297 100644 --- a/src/chttpd/src/chttpd_view.erl +++ b/src/chttpd/src/chttpd_view.erl @@ -91,19 +91,19 @@ handle_view_req(#httpd{method='POST', Keys = couch_mrview_util:get_view_keys(Props), Queries = couch_mrview_util:get_view_queries(Props), case {Queries, Keys} of - {Queries, undefined} when is_list(Queries) -> - [couch_stats:increment_counter([couchdb, httpd, view_reads]) || _I <- Queries], - multi_query_view(Req, Db, DDoc, ViewName, Queries); {undefined, Keys} when is_list(Keys) -> couch_stats:increment_counter([couchdb, httpd, view_reads]), design_doc_view(Req, Db, DDoc, ViewName, Keys); {undefined, undefined} -> throw({ bad_request, - "POST body must contain `keys` or `queries` field" + "POST body must contain `keys` field" }); {_, _} -> - throw({bad_request, "`keys` and `queries` are mutually exclusive"}) + throw({ + bad_request, + "The `queries` parameter is no longer supported at this endpoint" + }) end; handle_view_req(Req, _Db, _DDoc) -> From 10a3a591ad08eea3635a6bd686a9a77458d85df8 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Tue, 24 Sep 2019 14:56:05 -0400 Subject: [PATCH 2/2] Refactor based on review feedback --- src/chttpd/src/chttpd_view.erl | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl index 42c3afdf297..0d3d86d1a2a 100644 --- a/src/chttpd/src/chttpd_view.erl +++ b/src/chttpd/src/chttpd_view.erl @@ -88,21 +88,15 @@ handle_view_req(#httpd{method='POST', path_parts=[_, _, _, _, ViewName]}=Req, Db, DDoc) -> chttpd:validate_ctype(Req, "application/json"), Props = couch_httpd:json_body_obj(Req), - Keys = couch_mrview_util:get_view_keys(Props), - Queries = couch_mrview_util:get_view_queries(Props), - case {Queries, Keys} of - {undefined, Keys} when is_list(Keys) -> + assert_no_queries_param(couch_mrview_util:get_view_queries(Props)), + case couch_mrview_util:get_view_keys(Props) of + Keys when is_list(Keys) -> couch_stats:increment_counter([couchdb, httpd, view_reads]), design_doc_view(Req, Db, DDoc, ViewName, Keys); - {undefined, undefined} -> + _ -> throw({ bad_request, - "POST body must contain `keys` field" - }); - {_, _} -> - throw({ - bad_request, - "The `queries` parameter is no longer supported at this endpoint" + "POST body must contain an array called `keys`" }) end; @@ -113,6 +107,14 @@ handle_temp_view_req(Req, _Db) -> Msg = <<"Temporary views are not supported in CouchDB">>, chttpd:send_error(Req, 410, gone, Msg). +% See https://github.com/apache/couchdb/issues/2168 +assert_no_queries_param(undefined) -> + ok; +assert_no_queries_param(_) -> + throw({ + bad_request, + "The `queries` parameter is no longer supported at this endpoint" + }). -ifdef(TEST).