Skip to content

Commit

Permalink
make the authentication redirect URL configurable. setting it to the …
Browse files Browse the repository at this point in the history
…empty string yields the 0.11 behavior

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957805 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jchris committed Jun 25, 2010
1 parent a388698 commit 6d88c8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions etc/couchdb/default.ini.tpl.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions src/couchdb/couch_httpd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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, <<AuthRedirectBin/binary,"?return=",UrlReturn/binary,"&reason=",UrlReason/binary>>)}]}
end
end;
_Else ->
{Code, []}
Expand Down
1 change: 0 additions & 1 deletion src/couchdb/couch_rep_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ write_bulk_docs(#http_db{headers = Headers} = Db, Docs) ->
body = {[{new_edits, false}, {docs, JsonDocs}]},
headers = couch_util:proplist_apply_field({"Content-Type", "application/json"}, [{"X-Couch-Full-Commit", "false"} | Headers])
},
?LOG_ERROR("headers ~p",[Request#http_db.headers]),
ErrorsJson = case couch_rep_httpc:request(Request) of
{FailProps} ->
exit({target_error, couch_util:get_value(<<"error">>, FailProps)});
Expand Down

0 comments on commit 6d88c8c

Please sign in to comment.