Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3843217904 for ; Wed, 4 Feb 2015 15:49:38 +0000 (UTC) Received: (qmail 76572 invoked by uid 500); 4 Feb 2015 15:49:39 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 76446 invoked by uid 500); 4 Feb 2015 15:49:39 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 76408 invoked by uid 99); 4 Feb 2015 15:49:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Feb 2015 15:49:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id E9ADFE03EB; Wed, 4 Feb 2015 15:49:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Wed, 04 Feb 2015 15:49:39 -0000 Message-Id: <951c6f301cbb41c68888d1e3b30c6f6c@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Thu Jan 29 13:34:31 2015 -0800 Committer: ILYA Khlopotov 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),