summaryrefslogtreecommitdiff
path: root/src/couchdb
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2008-08-31 09:52:47 +0000
committerChristopher Lenz <cmlenz@apache.org>2008-08-31 09:52:47 +0000
commitf6920b7dc3f4593fa6eef5ae0ccc5e1a09c900bb (patch)
tree1a2ecd185de362ccdaa0bdb8c66572e398be369c /src/couchdb
parent15a175144d83d6177e9bbb923a7f7157e5ea8917 (diff)
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.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@690670 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb')
-rw-r--r--src/couchdb/couch_httpd.erl48
1 files changed, 28 insertions, 20 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 048445a9..e30f028f 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -787,24 +787,32 @@ handle_attachment_request(_Req, _Method, _DbName, _Db, _DocId, _FileName) ->
% 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});
+
+% 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}
+ ]});
% PUT /_config/Section/Option
% "value"
-handle_config_request(_Req, 'PUT', {[Section, Option]}) ->
- handle_config_request(_Req, 'POST', {[Section, Option]});
-
-% POST,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 @@ handle_config_request(Req, 'GET', {[Section, Option]}) ->
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 @@ handle_config_request(Req, 'DELETE', {[Section, Option]}) ->
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.