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:39 UTC
[2/4] chttpd commit: updated refs/heads/master to 81c938a
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),