From 70155ce87a85a5b70a225f350863e7ed50097345 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Tue, 16 Sep 2008 20:24:48 +0000 Subject: Add HTTP API for getting the complete config, and add a page to Futon that displays the configuration. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@696041 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_config.erl | 2 +- src/couchdb/couch_httpd.erl | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl index 6822dc5c..8bce5718 100644 --- a/src/couchdb/couch_config.erl +++ b/src/couchdb/couch_config.erl @@ -158,4 +158,4 @@ handle_info({'DOWN', _, _, DownPid, _}, #config{notify_funs=PidFuns}=Config) -> terminate(_Reason, _State) -> ok. %% @doc Unused -code_change(_OldVersion, State, _Extra) -> {ok, State}. \ No newline at end of file +code_change(_OldVersion, State, _Extra) -> {ok, State}. diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index b30ef7ee..604e1454 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -207,10 +207,14 @@ handle_db_request(Req, 'PUT', {DbName, []}) -> couch_db:close(Db), send_json(Req, 201, {[{ok, true}]}); {error, database_already_exists} -> - Msg = io_lib:format("Database ~p already exists.", [DbName]), + Msg = io_lib:format("Database ~p already exists.", [ + binary_to_list(DbName) + ]), throw({database_already_exists, Msg}); Error -> - Msg = io_lib:format("Error creating database ~p: ~p", [DbName, Error]), + Msg = io_lib:format("Error creating database ~p: ~p", [ + binary_to_list(DbName), Error + ]), throw({unknown_error, Msg}) end; @@ -805,6 +809,22 @@ handle_config_request(_Req, Method, {config, Config}) -> Parts = string:tokens(Config, "/"), handle_config_request(_Req, Method, {Parts}); +% GET /_config +handle_config_request(Req, 'GET', {[]}) -> + send_json(Req, 200, {dict:to_list(dict:map( + fun(_, Value) -> {Value} end, + lists:foldl( + fun({{Section, Option}, Value}, Acc) -> + SecBin = list_to_binary(Section), + OptBin = list_to_binary(Option), + ValBin = list_to_binary(Value), + dict:append(SecBin, {OptBin, ValBin}, Acc) + end, + dict:new(), + couch_config:all() + ) + ))}); + % GET /_config/Section handle_config_request(Req, 'GET', {[Section]}) -> KVs = [ -- cgit v1.2.3