From 1c7fc943c0aaf1fc41df8fa8dd431a95c302400a Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Sun, 18 May 2008 12:28:57 +0000 Subject: - more graceful handling of unknown private URIs including more user friendly messages - add a proper comment to the descending=false handling git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@657552 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 9ebb0b93..bdb23e78 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -96,6 +96,8 @@ handle_request0(Req, DocumentRoot, Method, Path) -> {ok, Req:respond({301, [{"Location", "/_utils/"}], <<>>})}; "/_utils/" ++ PathInfo -> {ok, Req:serve_file(PathInfo, DocumentRoot)}; + "/_" ++ UnknownPrivatePath -> + handle_unkown_private_uri_request(Req, Method, UnknownPrivatePath); _Else -> handle_db_request(Req, Method, {Path}) end. @@ -129,6 +131,19 @@ handle_replicate_request(Req, 'POST') -> handle_replicate_request(_Req, _Method) -> throw({method_not_allowed, "POST"}). +handle_unkown_private_uri_request(Req, _Method, UnknownPrivatePath) -> + KnownPrivatePaths = ["_utils"], + Msg = {obj, + [ + {error, "Sorry, we could not find the private path '_" ++ + mochiweb_util:unquote(UnknownPrivatePath) ++ + "' you are looking for. We only know about the following path(s): '" ++ + lists:flatten(KnownPrivatePaths) ++ "'"} + ] + }, + io:format("Debug: ~p~n", [Msg]), + send_error(Req, 404, Msg). + % Database request handlers handle_db_request(Req, Method, {Path}) -> @@ -631,7 +646,10 @@ parse_view_query(Req) -> Args %already reversed end; {"descending", "false"} -> - % ignore + % The descending=false behaviour is the default behaviour, so we + % simpply ignore it. This is only for convenience when playing with + % the HTTP API, so that a user doesn't get served an error when + % flipping true to false in the descending option. Args; {"skip", Value} -> case (catch list_to_integer(Value)) of -- cgit v1.2.3