Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 71084 invoked from network); 18 Apr 2009 18:37:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Apr 2009 18:37:11 -0000 Received: (qmail 96871 invoked by uid 500); 18 Apr 2009 18:37:11 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 96792 invoked by uid 500); 18 Apr 2009 18:37:10 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 96783 invoked by uid 99); 18 Apr 2009 18:37:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Apr 2009 18:37:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Apr 2009 18:37:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B34C52388A1B; Sat, 18 Apr 2009 18:36:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r766374 - in /couchdb/branches/0.9.x: ./ etc/default/couchdb share/www/script/test/basics.js share/www/script/test/view_errors.js src/couchdb/couch_httpd_db.erl src/couchdb/couch_httpd_view.erl Date: Sat, 18 Apr 2009 18:36:47 -0000 To: commits@couchdb.apache.org From: davisp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090418183647.B34C52388A1B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: davisp Date: Sat Apr 18 18:36:47 2009 New Revision: 766374 URL: http://svn.apache.org/viewvc?rev=766374&view=rev Log: Merged 766373 from trunk. Modified: couchdb/branches/0.9.x/ (props changed) couchdb/branches/0.9.x/etc/default/couchdb (props changed) couchdb/branches/0.9.x/share/www/script/test/basics.js couchdb/branches/0.9.x/share/www/script/test/view_errors.js couchdb/branches/0.9.x/src/couchdb/couch_httpd_db.erl couchdb/branches/0.9.x/src/couchdb/couch_httpd_view.erl Propchange: couchdb/branches/0.9.x/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Apr 18 18:36:47 2009 @@ -1,3 +1,3 @@ /couchdb/branches/design_resources:751716-751803 /couchdb/branches/form:729440-730015 -/couchdb/trunk:758717,760442,760503,760532,760535,760537-760539,761343,761347-761348,761352-761353,761355,762016,765420,766347,766353,766358 +/couchdb/trunk:758717,760442,760503,760532,760535,760537-760539,761343,761347-761348,761352-761353,761355,762016,765420,766347,766353,766358,766373 Propchange: couchdb/branches/0.9.x/etc/default/couchdb ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Sat Apr 18 18:36:47 2009 @@ -1,4 +1,4 @@ /couchdb/branches/design_resources/etc/default/couchdb:751716-751803 /couchdb/branches/form/etc/default/couchdb:729440-730015 -/couchdb/trunk/etc/default/couchdb:758717,760442,760503,760532,760535,760537-760539,761343,761347-761348,761352-761353,761355,762016,765420,766347,766353,766358 +/couchdb/trunk/etc/default/couchdb:758717,760442,760503,760532,760535,760537-760539,761343,761347-761348,761352-761353,761355,762016,765420,766347,766353,766358,766373 /incubator/couchdb/trunk/etc/default/couchdb:642419-694440 Modified: couchdb/branches/0.9.x/share/www/script/test/basics.js URL: http://svn.apache.org/viewvc/couchdb/branches/0.9.x/share/www/script/test/basics.js?rev=766374&r1=766373&r2=766374&view=diff ============================================================================== --- couchdb/branches/0.9.x/share/www/script/test/basics.js (original) +++ couchdb/branches/0.9.x/share/www/script/test/basics.js Sat Apr 18 18:36:47 2009 @@ -145,4 +145,32 @@ // deleting a non-existent doc should be 404 xhr = CouchDB.request("DELETE", "/test_suite_db/doc-does-not-exist"); T(xhr.status == 404); + + // Check some common error responses. + // PUT body not an object + xhr = CouchDB.request("PUT", "/test_suite_db/bar", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Document must be a JSON object"); + + // Body of a _bulk_docs is not an object + xhr = CouchDB.request("POST", "/test_suite_db/_bulk_docs", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + + // Body of an _all_docs multi-get is not a {"key": [...]} structure. + xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + var data = "{\"keys\": 1}"; + xhr = CouchDB.request("POST", "/test_suite_db/_all_docs", {body:data}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "`keys` member must be a array."); }; Modified: couchdb/branches/0.9.x/share/www/script/test/view_errors.js URL: http://svn.apache.org/viewvc/couchdb/branches/0.9.x/share/www/script/test/view_errors.js?rev=766374&r1=766373&r2=766374&view=diff ============================================================================== --- couchdb/branches/0.9.x/share/www/script/test/view_errors.js (original) +++ couchdb/branches/0.9.x/share/www/script/test/view_errors.js Sat Apr 18 18:36:47 2009 @@ -94,4 +94,18 @@ } catch(e) { T(e.error == "query_parse_error"); } + + // Check error responses for invalid multi-get bodies. + var path = "/test_suite_db/_design/test/_view/no_reduce"; + var xhr = CouchDB.request("POST", path, {body: "[]"}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "Body must be a JSON object"); + var data = "{\"keys\": 1}"; + xhr = CouchDB.request("POST", path, {body:data}); + T(xhr.status == 400); + result = JSON.parse(xhr.responseText); + T(result.error == "bad_request"); + T(result.reason == "`keys` member must be a array."); }; Modified: couchdb/branches/0.9.x/src/couchdb/couch_httpd_db.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.9.x/src/couchdb/couch_httpd_db.erl?rev=766374&r1=766373&r2=766374&view=diff ============================================================================== --- couchdb/branches/0.9.x/src/couchdb/couch_httpd_db.erl (original) +++ couchdb/branches/0.9.x/src/couchdb/couch_httpd_db.erl Sat Apr 18 18:36:47 2009 @@ -113,7 +113,13 @@ db_req(#httpd{method='POST',path_parts=[_,<<"_bulk_docs">>]}=Req, Db) -> couch_stats_collector:increment({httpd, bulk_requests}), - {JsonProps} = couch_httpd:json_body(Req), + JsonProps = + case couch_httpd:json_body(Req) of + {Fields} -> + Fields; + _ -> + throw({bad_request, "Body must be a JSON object"}) + end, DocsArray = proplists:get_value(<<"docs">>, JsonProps), case couch_httpd:header_value(Req, "X-Couch-Full-Commit", "false") of "true" -> @@ -214,9 +220,20 @@ all_docs_view(Req, Db, nil); db_req(#httpd{method='POST',path_parts=[_,<<"_all_docs">>]}=Req, Db) -> - {Props} = couch_httpd:json_body(Req), - Keys = proplists:get_value(<<"keys">>, Props, nil), - all_docs_view(Req, Db, Keys); + case couch_httpd:json_body(Req) of + {Fields} -> + case proplists:get_value(<<"keys">>, Fields, nil) of + nil -> + ?LOG_DEBUG("POST to _all_docs with no keys member.", []), + all_docs_view(Req, Db, nil); + Keys when is_list(Keys) -> + all_docs_view(Req, Db, Keys); + _ -> + throw({bad_request, "`keys` member must be a array."}) + end; + _ -> + throw({bad_request, "Body must be a JSON object"}) + end; db_req(#httpd{path_parts=[_,<<"_all_docs">>]}=Req, _Db) -> send_method_not_allowed(Req, "GET,HEAD,POST"); Modified: couchdb/branches/0.9.x/src/couchdb/couch_httpd_view.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.9.x/src/couchdb/couch_httpd_view.erl?rev=766374&r1=766373&r2=766374&view=diff ============================================================================== --- couchdb/branches/0.9.x/src/couchdb/couch_httpd_view.erl (original) +++ couchdb/branches/0.9.x/src/couchdb/couch_httpd_view.erl Sat Apr 18 18:36:47 2009 @@ -55,9 +55,21 @@ 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, DName, ViewName, Keys); + case couch_httpd:json_body(Req) of + {Fields} -> + 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]), + design_doc_view(Req, Db, DName, ViewName, nil); + Keys when is_list(Keys) -> + design_doc_view(Req, Db, DName, ViewName, Keys); + _ -> + throw({bad_request, "`keys` member must be a array."}) + end; + _ -> + throw({bad_request, "Body must be a JSON object"}) + end; handle_view_req(Req, _Db) -> send_method_not_allowed(Req, "GET,POST,HEAD").