diff --git a/etc/couchdb/default.ini.tpl.in b/etc/couchdb/default.ini.tpl.in index 7b9ac37c7..af6b9bf44 100644 --- a/etc/couchdb/default.ini.tpl.in +++ b/etc/couchdb/default.ini.tpl.in @@ -29,6 +29,7 @@ include_sasl = true [couch_httpd_auth] authentication_db = _users +authentication_redirect = /_utils/session.html require_valid_user = false timeout = 600 ; number of seconds before automatic logout auth_cache_size = 50 ; size is number of cache entries diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 1049aa9d5..ef930147b 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -745,14 +745,19 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) -> % redirect to the session page. case ErrorStr of <<"unauthorized">> -> - % if the accept header matches html, then do the redirect. else proceed as usual. - case re:run(MochiReq:get_header_value("Accept"), "html", [{capture, none}]) of - nomatch -> - {Code, []}; - match -> - UrlReturn = ?l2b(couch_util:url_encode(MochiReq:get(path))), - UrlReason = ?l2b(couch_util:url_encode(ReasonStr)), - {302, [{"Location", couch_httpd:absolute_uri(Req, <<"/_utils/session.html?return=",UrlReturn/binary,"&reason=",UrlReason/binary>>)}]} + case couch_config:get("couch_httpd_auth", "authentication_redirect", nil) of + nil -> {Code, []}; + AuthRedirect -> + % if the accept header matches html, then do the redirect. else proceed as usual. + case re:run(MochiReq:get_header_value("Accept"), "html", [{capture, none}]) of + nomatch -> + {Code, []}; + match -> + AuthRedirectBin = ?l2b(AuthRedirect), + UrlReturn = ?l2b(couch_util:url_encode(MochiReq:get(path))), + UrlReason = ?l2b(couch_util:url_encode(ReasonStr)), + {302, [{"Location", couch_httpd:absolute_uri(Req, < exit({target_error, couch_util:get_value(<<"error">>, FailProps)});