On Mon, May 23, 2011 at 8:39 AM,  <[email protected]> wrote:
> Author: benoitc
> Date: Mon May 23 06:39:47 2011
> New Revision: 1126332
>
> URL: http://svn.apache.org/viewvc?rev=1126332&view=rev
> Log:
> Fix authentication. Jquery append "*.*" to accept  by
> default so if we test text/html first it will alway be true. Then test
> first if application/json was given and then test if text/html then
> others.
>
>
> Modified:
>    couchdb/trunk/src/couchdb/couch_httpd.erl
>
> Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
> URL: 
> http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=1126332&r1=1126331&r2=1126332&view=diff
> ==============================================================================
> --- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
> +++ couchdb/trunk/src/couchdb/couch_httpd.erl Mon May 23 06:39:47 2011
> @@ -768,24 +768,29 @@ error_headers(#httpd{mochi_req=MochiReq}
>                             % 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("text/html") 
> of
> -                            false ->
> -                                {Code, []};
> +                            case 
> MochiReq:accepts_content_type("application/json") 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)}]}
> +                                {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 ->
> +                                    {Code, []}
> +                                end
>                             end
>                         end
>                     end;
>
>
>

We should probably merged it in 1.1.x too since it fixes a regression
compared to 1.0.x

- benoît

Reply via email to