iilyak commented on a change in pull request #3568:
URL: https://github.com/apache/couchdb/pull/3568#discussion_r635211952



##########
File path: src/couch/src/couch_httpd.erl
##########
@@ -605,62 +630,106 @@ error_info({Error, Reason}) ->
 error_info(Error) ->
     {500, <<"unknown_error">>, couch_util:to_binary(Error)}.
 
-error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) ->
-    if Code == 401 ->
-        % 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", 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", undefined) of
-                    undefined -> {Code, []};
-                    AuthRedirect ->
-                        case config:get("couch_httpd_auth", 
"require_valid_user", "false") of
-                        "true" ->
-                            % send the browser popup header no matter what if 
we are require_valid_user
-                            {Code, [{"WWW-Authenticate", "Basic 
realm=\"server\""}]};
-                        _False ->
-                            case 
MochiReq:accepts_content_type("application/json") of
-                            true ->
-                                {Code, []};
-                            false ->
-                                case 
MochiReq:accepts_content_type("text/html") of
-                                true ->
-                                    % Redirect to the path the user requested, 
not
-                                    % the one that is used internally.
-                                    UrlReturnRaw = case 
MochiReq:get_header_value("x-couchdb-vhost-path") of
-                                    undefined ->
-                                        MochiReq:get(path);
-                                    VHostPath ->
-                                        VHostPath
-                                    end,
-                                    RedirectLocation = lists:flatten([
-                                        AuthRedirect,
-                                        "?return=", 
couch_util:url_encode(UrlReturnRaw),
-                                        "&reason=", 
couch_util:url_encode(ReasonStr)
-                                    ]),
-                                    {302, [{"Location", absolute_uri(Req, 
RedirectLocation)}]};
-                                false ->
+error_headers(#httpd{mochi_req = MochiReq} = Req, Code, ErrorStr, ReasonStr) ->

Review comment:
       I think we need to eventually tidy up this function.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to