You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2008/08/31 11:52:48 UTC
svn commit: r690670 - /incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
Author: cmlenz
Date: Sun Aug 31 02:52:47 2008
New Revision: 690670
URL: http://svn.apache.org/viewvc?rev=690670&view=rev
Log:
Fix the config HTTP API for the changed JSON representation, remove the POST handling for setting option values (leaving only PUT), and add a GET /_config/section handler that allows enumerating the options in a section.
Modified:
incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=690670&r1=690669&r2=690670&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Sun Aug 31 02:52:47 2008
@@ -787,24 +787,32 @@
% Config request handlers
handle_config_request(_Req, Method, {config, Config}) ->
- [Section, Option] = string:tokens(Config, "/"),
- handle_config_request(_Req, Method, {[Section, Option]});
+ Parts = string:tokens(Config, "/"),
+ handle_config_request(_Req, Method, {Parts});
-% PUT /_config/Section/Option
-% "value"
-handle_config_request(_Req, 'PUT', {[Section, Option]}) ->
- handle_config_request(_Req, 'POST', {[Section, Option]});
+% GET /_config/Section
+handle_config_request(Req, 'GET', {[Section]}) ->
+ Options = [
+ {[{name, list_to_binary(Option)}, {value, list_to_binary(Value)}]} ||
+ {Option, Value} <-
+ couch_config:lookup_match({{Section, '$1'}, '$2'}, [])
+ ],
+ send_json(Req, 200, {[
+ {ok, true},
+ {section, list_to_binary(Section)},
+ {options, Options}
+ ]});
-% POST,PUT /_config/Section/Option
+% PUT /_config/Section/Option
% "value"
-handle_config_request(Req, 'POST', {[Section, Option]}) ->
+handle_config_request(Req, 'PUT', {[Section, Option]}) ->
Value = binary_to_list(Req:recv_body()),
ok = couch_config:store({Section, Option}, Value),
- send_json(Req, 200, {obj, [
+ send_json(Req, 200, {[
{ok, true},
- {section, Section},
- {name, Option},
- {value, Value}
+ {section, list_to_binary(Section)},
+ {name, list_to_binary(Option)},
+ {value, list_to_binary(Value)}
]});
% GET /_config/Section/Option
@@ -813,11 +821,11 @@
null ->
throw({not_found, unknown_config_value});
Value ->
- send_json(Req, 200, {obj, [
+ send_json(Req, 200, {[
{ok, true},
- {section, Section},
- {name, Option},
- {value, Value}
+ {section, list_to_binary(Section)},
+ {name, list_to_binary(Option)},
+ {value, list_to_binary(Value)}
]})
end;
@@ -828,11 +836,11 @@
throw({not_found, unknown_config_value});
OldValue ->
couch_config:unset({Section, Option}),
- send_json(Req, 200, {obj, [
+ send_json(Req, 200, {[
{ok, true},
- {section, Section},
- {name, Option},
- {old_value, OldValue}
+ {section, list_to_binary(Section)},
+ {name, list_to_binary(Option)},
+ {value, list_to_binary(OldValue)}
]})
end.