Author: fdmanana Date: Wed Dec 1 18:10:09 2010 New Revision: 1041113 URL: http://svn.apache.org/viewvc?rev=1041113&view=rev Log: Merged revision 1041103 from trunk:
Proper verification of the accepted content types plus some code cleaning. Modified: couchdb/branches/1.1.x/src/couchdb/couch_httpd.erl Modified: couchdb/branches/1.1.x/src/couchdb/couch_httpd.erl URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_httpd.erl?rev=1041113&r1=1041112&r2=1041113&view=diff ============================================================================== --- couchdb/branches/1.1.x/src/couchdb/couch_httpd.erl (original) +++ couchdb/branches/1.1.x/src/couchdb/couch_httpd.erl Wed Dec 1 18:10:09 2010 @@ -757,31 +757,24 @@ 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 -> - % if the accept header matches html, then do the redirect. else proceed as usual. - Accepts = case MochiReq:get_header_value("Accept") of - undefined -> - % According to the HTTP 1.1 spec, if the Accept - % header is missing, it means the client accepts - % all media types. - "html"; - Else -> - Else - end, - case re:run(Accepts, "\\bhtml\\b", - [{capture, none}, caseless]) of - nomatch -> + case MochiReq:accepts_content_type("text/html") of + false -> {Code, []}; - match -> - AuthRedirectBin = ?l2b(AuthRedirect), + 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 + undefined -> + MochiReq:get(path); + VHostPath -> + VHostPath end, - UrlReturn = ?l2b(couch_util:url_encode(UrlReturnRaw)), - UrlReason = ?l2b(couch_util:url_encode(ReasonStr)), - {302, [{"Location", couch_httpd:absolute_uri(Req, <<AuthRedirectBin/binary,"?return=",UrlReturn/binary,"&reason=",UrlReason/binary>>)}]} + RedirectLocation = lists:flatten([ + AuthRedirect, + "?return=", couch_util:url_encode(UrlReturnRaw), + "&reason=", couch_util:url_encode(ReasonStr) + ]), + {302, [{"Location", absolute_uri(Req, RedirectLocation)}]} end end end;