From 016ede4b458db2e006914f5cd7d157fb42ff0733 Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Mon, 8 Dec 2014 07:45:00 -0800 Subject: [PATCH 1/2] Return error when open_revs=all and document doesn't exist COUCHDB-2517 --- src/chttpd_db.erl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl index 24eb78c..79d832b 100644 --- a/src/chttpd_db.erl +++ b/src/chttpd_db.erl @@ -582,6 +582,10 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) -> undefined -> []; AcceptHeader -> string:tokens(AcceptHeader, ", ") end, + case Results of + [] when Revs == all -> + chttpd:send_error(Req, {not_found, missing}); + _Else -> case lists:member("multipart/mixed", AcceptedTypes) of false -> {ok, Resp} = start_json_response(Req, 200), @@ -608,6 +612,7 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) -> true -> send_docs_multipart(Req, Results, Options) end + end end; db_doc_req(#httpd{method='POST', user_ctx=Ctx}=Req, Db, DocId) -> From c256e919220b298b7ab14074a68c1ff91bacf12a Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Mon, 8 Dec 2014 07:46:46 -0800 Subject: [PATCH 2/2] Re-indent to reflect recent addtion of a case branch COUCHDB-2517 --- src/chttpd_db.erl | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl index 79d832b..e4510ae 100644 --- a/src/chttpd_db.erl +++ b/src/chttpd_db.erl @@ -586,32 +586,32 @@ db_doc_req(#httpd{method='GET'}=Req, Db, DocId) -> [] when Revs == all -> chttpd:send_error(Req, {not_found, missing}); _Else -> - case lists:member("multipart/mixed", AcceptedTypes) of - false -> - {ok, Resp} = start_json_response(Req, 200), - send_chunk(Resp, "["), - % We loop through the docs. The first time through the separator - % is whitespace, then a comma on subsequent iterations. - lists:foldl( - fun(Result, AccSeparator) -> - case Result of - {ok, Doc} -> - JsonDoc = couch_doc:to_json_obj(Doc, Options), - Json = ?JSON_ENCODE({[{ok, JsonDoc}]}), - send_chunk(Resp, AccSeparator ++ Json); - {{not_found, missing}, RevId} -> - RevStr = couch_doc:rev_to_str(RevId), - Json = ?JSON_ENCODE({[{<<"missing">>, RevStr}]}), - send_chunk(Resp, AccSeparator ++ Json) - end, - "," % AccSeparator now has a comma - end, - "", Results), - send_chunk(Resp, "]"), - end_json_response(Resp); - true -> - send_docs_multipart(Req, Results, Options) - end + case lists:member("multipart/mixed", AcceptedTypes) of + false -> + {ok, Resp} = start_json_response(Req, 200), + send_chunk(Resp, "["), + % We loop through the docs. The first time through the separator + % is whitespace, then a comma on subsequent iterations. + lists:foldl( + fun(Result, AccSeparator) -> + case Result of + {ok, Doc} -> + JsonDoc = couch_doc:to_json_obj(Doc, Options), + Json = ?JSON_ENCODE({[{ok, JsonDoc}]}), + send_chunk(Resp, AccSeparator ++ Json); + {{not_found, missing}, RevId} -> + RevStr = couch_doc:rev_to_str(RevId), + Json = ?JSON_ENCODE({[{<<"missing">>, RevStr}]}), + send_chunk(Resp, AccSeparator ++ Json) + end, + "," % AccSeparator now has a comma + end, + "", Results), + send_chunk(Resp, "]"), + end_json_response(Resp); + true -> + send_docs_multipart(Req, Results, Options) + end end end;