summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-04-06 17:39:22 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-04-07 12:18:29 -0400
commit2ba98a89cda88ccc9be2b4e4fb481086d1364e42 (patch)
treed4fe047ae033414a2a94c89f20185f63189eb9e7
parent5652e72e43406b7e4b743ee3fe7e2570aec77e95 (diff)
downloadcouchdb-2ba98a89cda88ccc9be2b4e4fb481086d1364e42.tar.gz
Return better responses for endpoints which are not implemented
Endpoints which are removed return a 410 response: - _show - _list - _rewrite Endpoints which will be implemented in CouchDB 4.x eventually now return a 510 response: - _purge - _purge_infos_limit Endpoints which return a 2xx but are a no-op effectively: - _compact - _view_cleanup
-rw-r--r--src/chttpd/src/chttpd_db.erl21
-rw-r--r--src/chttpd/src/chttpd_httpd_handlers.erl32
-rw-r--r--src/chttpd/src/chttpd_view.erl5
3 files changed, 35 insertions, 23 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index e9b33f001..deaca4855 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -252,21 +252,14 @@ maybe_flush_changes_feed(Acc0, Data, Len) ->
},
{ok, Acc}.
-handle_compact_req(#httpd{method='POST'}=Req, Db) ->
+
+% Return the same response as if a compaction succeeded even though _compaction
+% isn't a valid operation in CouchDB >= 4.x anymore. This is mostly to not
+% break existing user script which maybe periodically call this endpoint. In
+% the future this endpoint will return a 410 response then it will be removed.
+handle_compact_req(#httpd{method='POST'}=Req, _Db) ->
chttpd:validate_ctype(Req, "application/json"),
- case Req#httpd.path_parts of
- [_DbName, <<"_compact">>] ->
- ok = fabric:compact(Db),
- send_json(Req, 202, {[{ok, true}]});
- [DbName, <<"_compact">>, DesignName | _] ->
- case ddoc_cache:open(DbName, <<"_design/", DesignName/binary>>) of
- {ok, _DDoc} ->
- ok = fabric:compact(Db, DesignName),
- send_json(Req, 202, {[{ok, true}]});
- Error ->
- throw(Error)
- end
- end;
+ send_json(Req, 202, {[{ok, true}]});
handle_compact_req(Req, _Db) ->
send_method_not_allowed(Req, "POST").
diff --git a/src/chttpd/src/chttpd_httpd_handlers.erl b/src/chttpd/src/chttpd_httpd_handlers.erl
index 831c014b3..be6c0a13e 100644
--- a/src/chttpd/src/chttpd_httpd_handlers.erl
+++ b/src/chttpd/src/chttpd_httpd_handlers.erl
@@ -14,6 +14,13 @@
-export([url_handler/1, db_handler/1, design_handler/1, handler_info/3]).
+-export([
+ not_supported/2,
+ not_supported/3,
+ not_implemented/2
+]).
+
+
-include_lib("couch/include/couch_db.hrl").
@@ -32,20 +39,22 @@ url_handler(<<"_session">>) -> fun chttpd_auth:handle_session_req/1;
url_handler(<<"_up">>) -> fun chttpd_misc:handle_up_req/1;
url_handler(_) -> no_match.
-db_handler(<<"_view_cleanup">>) -> fun chttpd_db:handle_view_cleanup_req/2;
+db_handler(<<"_view_cleanup">>) -> fun ?MODULE:not_implemented/2;
db_handler(<<"_compact">>) -> fun chttpd_db:handle_compact_req/2;
db_handler(<<"_design">>) -> fun chttpd_db:handle_design_req/2;
db_handler(<<"_partition">>) -> fun chttpd_db:handle_partition_req/2;
-db_handler(<<"_temp_view">>) -> fun chttpd_view:handle_temp_view_req/2;
+db_handler(<<"_temp_view">>) -> fun ?MODULE:not_supported/2;
db_handler(<<"_changes">>) -> fun chttpd_db:handle_changes_req/2;
+db_handler(<<"_purge">>) -> fun ?MODULE:not_implemented/2;
+db_handler(<<"_purged_infos_limit">>) -> fun ?MODULE:not_implemented/2;
db_handler(_) -> no_match.
design_handler(<<"_view">>) -> fun chttpd_view:handle_view_req/3;
-design_handler(<<"_show">>) -> fun chttpd_show:handle_doc_show_req/3;
-design_handler(<<"_list">>) -> fun chttpd_show:handle_view_list_req/3;
+design_handler(<<"_show">>) -> fun ?MODULE:not_supported/3;
+design_handler(<<"_list">>) -> fun ?MODULE:not_supported/3;
design_handler(<<"_update">>) -> fun chttpd_show:handle_doc_update_req/3;
design_handler(<<"_info">>) -> fun chttpd_db:handle_design_info_req/3;
-design_handler(<<"_rewrite">>) -> fun chttpd_rewrite:handle_rewrite_req/3;
+design_handler(<<"_rewrite">>) -> fun ?MODULE:not_supported/3;
design_handler(_) -> no_match.
@@ -484,3 +493,16 @@ get_copy_destination(Req) ->
unknown
end.
+
+not_supported(#httpd{} = Req, Db, _DDoc) ->
+ not_supported(Req, Db).
+
+
+not_supported(#httpd{} = Req, _Db) ->
+ Msg = <<"resource is not supported in CouchDB >= 4.x">>,
+ chttpd:send_error(Req, 410, gone, Msg).
+
+
+not_implemented(#httpd{} = Req, _Db) ->
+ Msg = <<"resouce is not implemented">>,
+ chttpd:send_error(Req, 501, not_implemented, Msg).
diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index 49ca1a793..84997e5a5 100644
--- a/src/chttpd/src/chttpd_view.erl
+++ b/src/chttpd/src/chttpd_view.erl
@@ -14,7 +14,7 @@
-include_lib("couch/include/couch_db.hrl").
-include_lib("couch_mrview/include/couch_mrview.hrl").
--export([handle_view_req/3, handle_temp_view_req/2]).
+-export([handle_view_req/3]).
multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
Args0 = couch_mrview_http:parse_params(Req, undefined),
@@ -101,9 +101,6 @@ handle_view_req(#httpd{method='POST',
handle_view_req(Req, _Db, _DDoc) ->
chttpd:send_method_not_allowed(Req, "GET,POST,HEAD").
-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) ->