You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/02/04 16:49:38 UTC
[1/4] chttpd commit: updated refs/heads/master to 81c938a
Repository: couchdb-chttpd
Updated Branches:
refs/heads/master 444092698 -> 81c938a9f
Update config_listener behaviuor
COUCHDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/4b102bf7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/4b102bf7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/4b102bf7
Branch: refs/heads/master
Commit: 4b102bf7de3b835cf82c81276deb3e4afbd942d9
Parents: 1e41311
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 29 13:33:57 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 05:58:58 2015 -0800
----------------------------------------------------------------------
src/chttpd_config_listener.erl | 43 +++++++++----------------------------
src/chttpd_sup.erl | 2 +-
2 files changed, 11 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4b102bf7/src/chttpd_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_config_listener.erl b/src/chttpd_config_listener.erl
index cf90ab5..76fc396 100644
--- a/src/chttpd_config_listener.erl
+++ b/src/chttpd_config_listener.erl
@@ -11,24 +11,16 @@
% the License.
-module(chttpd_config_listener).
--behaviour(gen_server).
--vsn(1).
+-vsn(2).
-behaviour(config_listener).
% public interface
--export([start_link/0]).
-
-% gen_server callbacks
--export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- code_change/3, terminate/2]).
+-export([subscribe/0]).
% config_listener callback
--export([handle_config_change/5]).
-
-start_link() ->
- gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+-export([handle_config_change/5, handle_config_terminate/3]).
-init([]) ->
+subscribe() ->
Settings = [
{bind_address, config:get("chttpd", "bind_address")},
{port, config:get("chttpd", "port")},
@@ -36,7 +28,7 @@ init([]) ->
{server_options, config:get("chttpd", "server_options")}
],
ok = config:listen_for_changes(?MODULE, Settings),
- {ok, Settings}.
+ ok.
handle_config_change("chttpd", "bind_address", Value, _, Settings) ->
maybe_replace(bind_address, Value, Settings);
@@ -49,26 +41,11 @@ handle_config_change("chttpd", "server_options", Value, _, Settings) ->
handle_config_change(_, _, _, _, Settings) ->
{ok, Settings}.
-handle_call(_, _, State) ->
- {reply, ignored, State}.
-
-handle_cast(_, State) ->
- {noreply, State}.
-
-handle_info({gen_event_EXIT, {config_listener, ?MODULE}, _Reason}, State) ->
- erlang:send_after(5000, self(), restart_config_listener),
- {noreply, State};
-handle_info(restart_config_listener, State) ->
- ok = config:listen_for_changes(?MODULE, State),
- {noreply, State};
-handle_info(_Msg, State) ->
- {noreply, State}.
-
-terminate(_, _State) ->
- ok.
-
-code_change(_, State, _) ->
- {ok, State}.
+handle_config_terminate(_Server, _Reason, State) ->
+ spawn(fun() ->
+ timer:sleep(5000),
+ config:listen_for_changes(?MODULE, State)
+ end).
% private
maybe_replace(Key, Value, Settings) ->
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/4b102bf7/src/chttpd_sup.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_sup.erl b/src/chttpd_sup.erl
index 498491a..6763ffe 100644
--- a/src/chttpd_sup.erl
+++ b/src/chttpd_sup.erl
@@ -23,9 +23,9 @@ start_link(Args) ->
supervisor:start_link({local,?MODULE}, ?MODULE, Args).
init([]) ->
+ chttp_config_listener:subscribe(),
{ok, {{one_for_one, 3, 10}, [
?CHILD(chttpd, worker),
- ?CHILD(chttpd_config_listener, worker),
?CHILD(chttpd_auth_cache, worker),
{chttpd_auth_cache_lru,
{ets_lru, start_link, [chttpd_auth_cache_lru, lru_opts()]},
[2/4] chttpd commit: updated refs/heads/master to 81c938a
Posted by kx...@apache.org.
config:get/3 is more strict now
The config:get/3 supports only following types for default argument
- atom `undefined`
- string (list)
- boolean
- float
- integer
COUCDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/106f55a1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/106f55a1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/106f55a1
Branch: refs/heads/master
Commit: 106f55a13d6b080ca0474870cb50c99588be332b
Parents: 4b102bf
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Jan 29 13:34:31 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 05:58:59 2015 -0800
----------------------------------------------------------------------
src/chttpd.erl | 39 ++++++++++++++++++++++-----------------
src/chttpd_misc.erl | 8 ++++----
2 files changed, 26 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/106f55a1/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 9509462..87a59ee 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -50,20 +50,20 @@ start_link(http) ->
start_link(https) ->
Port = config:get("ssl", "port", "6984"),
- {ok, Ciphers} = couch_util:parse_term(config:get("ssl", "ciphers", "nil")),
- {ok, Versions} = couch_util:parse_term(config:get("ssl", "tls_versions", "nil")),
- {ok, SecureRenegotiate} = couch_util:parse_term(config:get("ssl", "secure_renegotiate", "nil")),
+ {ok, Ciphers} = couch_util:parse_term(config:get("ssl", "ciphers", undefined)),
+ {ok, Versions} = couch_util:parse_term(config:get("ssl", "tls_versions", undefined)),
+ {ok, SecureRenegotiate} = couch_util:parse_term(config:get("ssl", "secure_renegotiate", undefined)),
ServerOpts0 =
- [{cacertfile, config:get("ssl", "cacert_file", nil)},
- {keyfile, config:get("ssl", "key_file", nil)},
- {certfile, config:get("ssl", "cert_file", nil)},
- {password, config:get("ssl", "password", nil)},
+ [{cacertfile, config:get("ssl", "cacert_file", undefined)},
+ {keyfile, config:get("ssl", "key_file", undefined)},
+ {certfile, config:get("ssl", "cert_file", undefined)},
+ {password, config:get("ssl", "password", undefined)},
{secure_renegotiate, SecureRenegotiate},
{versions, Versions},
{ciphers, Ciphers}],
- case (couch_util:get_value(keyfile, ServerOpts0) == nil orelse
- couch_util:get_value(certfile, ServerOpts0) == nil) of
+ case (couch_util:get_value(keyfile, ServerOpts0) == undefined orelse
+ couch_util:get_value(certfile, ServerOpts0) == undefined) of
true ->
io:format("SSL enabled but PEM certificates are missing.", []),
throw({error, missing_certs});
@@ -71,7 +71,7 @@ start_link(https) ->
ok
end,
- ServerOpts = [Opt || {_, V}=Opt <- ServerOpts0, V /= nil],
+ ServerOpts = [Opt || {_, V}=Opt <- ServerOpts0, V /= undefined],
ClientOpts = case config:get("ssl", "verify_ssl_certificates", "false") of
"false" ->
@@ -85,8 +85,8 @@ start_link(https) ->
"ssl_certificate_max_depth", "1"))},
{fail_if_no_peer_cert, FailIfNoPeerCert},
{verify, verify_peer}] ++
- case config:get("ssl", "verify_fun", nil) of
- nil -> [];
+ case config:get("ssl", "verify_fun", undefined) of
+ undefined -> [];
SpecStr ->
[{verify_fun, couch_httpd:make_arity_3_fun(SpecStr)}]
end
@@ -100,10 +100,12 @@ start_link(https) ->
start_link(https, Options).
start_link(Name, Options) ->
+ IP = with_default(config:get("chttpd", "bind_address"), any),
+
Options1 = Options ++ [
{loop, fun ?MODULE:handle_request/1},
{name, Name},
- {ip, config:get("chttpd", "bind_address", any)}
+ {ip, IP}
],
ServerOptsCfg = config:get("chttpd", "server_options", "[]"),
{ok, ServerOpts} = couch_util:parse_term(ServerOptsCfg),
@@ -771,14 +773,14 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, 401=Code, ErrorStr, ReasonStr) ->
% this is where the basic auth popup is triggered
case MochiReq:get_header_value("X-CouchDB-WWW-Authenticate") of
undefined ->
- case config:get("httpd", "WWW-Authenticate", nil) of
- nil ->
+ case config:get("httpd", "WWW-Authenticate", undefined) of
+ undefined ->
% If the client is a browser and the basic auth popup isn't turned on
% redirect to the session page.
case ErrorStr of
<<"unauthorized">> ->
- case config:get("couch_httpd_auth", "authentication_redirect", nil) of
- nil -> {Code, []};
+ case config:get("couch_httpd_auth", "authentication_redirect", undefined) of
+ undefined -> {Code, []};
AuthRedirect ->
case config:get("couch_httpd_auth", "require_valid_user", "false") of
"true" ->
@@ -934,3 +936,6 @@ stack_trace_id(Stack) ->
stack_hash(Stack) ->
erlang:crc32(term_to_binary(Stack)).
+
+with_default(undefined, Default) -> Default;
+with_default(Value, _) -> Value.
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/106f55a1/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index ce23fd9..3b0f15e 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -266,8 +266,8 @@ handle_config_req(#httpd{method='PUT', path_parts=[_, Section, Key]}=Req) ->
send_json(Req, 200, list_to_binary(OldValue));
% GET /_config/Section/Key
handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
- case config:get(Section, Key, null) of
- null ->
+ case config:get(Section, Key, undefined) of
+ undefined ->
throw({not_found, unknown_config_value});
Value ->
send_json(Req, 200, list_to_binary(Value))
@@ -275,8 +275,8 @@ handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req) ->
% DELETE /_config/Section/Key
handle_config_req(#httpd{method='DELETE',path_parts=[_,Section,Key]}=Req) ->
Persist = chttpd:header_value(Req, "X-Couch-Persist") /= "false",
- case config:get(Section, Key, null) of
- null ->
+ case config:get(Section, Key, undefined) of
+ undefined ->
throw({not_found, unknown_config_value});
OldValue ->
config:delete(Section, Key, Persist),
[4/4] chttpd commit: updated refs/heads/master to 81c938a
Posted by kx...@apache.org.
Merge remote-tracking branch 'iilyak/2561-make-config-API-consistent'
This closes #21
COUCHDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/81c938a9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/81c938a9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/81c938a9
Branch: refs/heads/master
Commit: 81c938a9f59e2f9aa732cb772e41408a8d106098
Parents: 4440926 6f983d3
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Feb 4 18:43:16 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Wed Feb 4 18:43:16 2015 +0300
----------------------------------------------------------------------
src/chttpd.erl | 39 ++++++++++++++++++--------------
src/chttpd_config_listener.erl | 44 ++++++++++---------------------------
src/chttpd_misc.erl | 8 +++----
src/chttpd_sup.erl | 2 +-
4 files changed, 38 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
[3/4] chttpd commit: updated refs/heads/master to 81c938a
Posted by kx...@apache.org.
Don't restart event handler on termination
COUCHDB-2561
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/6f983d33
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/6f983d33
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/6f983d33
Branch: refs/heads/master
Commit: 6f983d3327f36b7fc61fd5aff1437646355268cb
Parents: 106f55a
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Jan 30 11:06:12 2015 -0800
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Wed Feb 4 05:58:59 2015 -0800
----------------------------------------------------------------------
src/chttpd_config_listener.erl | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6f983d33/src/chttpd_config_listener.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_config_listener.erl b/src/chttpd_config_listener.erl
index 76fc396..7087b81 100644
--- a/src/chttpd_config_listener.erl
+++ b/src/chttpd_config_listener.erl
@@ -41,6 +41,7 @@ handle_config_change("chttpd", "server_options", Value, _, Settings) ->
handle_config_change(_, _, _, _, Settings) ->
{ok, Settings}.
+handle_config_terminate(_, stop, _) -> ok;
handle_config_terminate(_Server, _Reason, State) ->
spawn(fun() ->
timer:sleep(5000),