Skip to content

Commit

Permalink
Fix authentication. Jquery append "*.*" to accept by
Browse files Browse the repository at this point in the history
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.



git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1126332 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Benoit Chesneau committed May 23, 2011
1 parent 1a426b2 commit ecb23f5
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/couchdb/couch_httpd.erl
Expand Up @@ -768,24 +768,29 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, Code, ErrorStr, ReasonStr) ->
% 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;
Expand Down

0 comments on commit ecb23f5

Please sign in to comment.