From 2d591fd1e45338215d1bdebd84884d8044779327 Mon Sep 17 00:00:00 2001 From: Filipe David Borba Manana Date: Wed, 1 Dec 2010 18:10:09 +0000 Subject: Merged revision 1041103 from trunk: Proper verification of the accepted content types plus some code cleaning. git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/1.1.x@1041113 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_httpd.erl | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/couchdb') diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 4bce7e02..6bd5c893 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -757,31 +757,24 @@ 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 -> - % 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, <