[ 
https://issues.apache.org/jira/browse/COUCHDB-1175?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15849316#comment-15849316
 ] 

Arturo Garcia-Vargas commented on COUCHDB-1175:
-----------------------------------------------

Hi All,

  Would the following break anything?  Seems to me like an *almost* proper 
negotiation done by mochiweb.  I would very much prefer to get the list of 
accepted content types in the order sent by the client in case of equal Q 
values (check mochi's comments on MochiReq:accepted_content_types/1) instead of 
the order set by the caller.

{code}
diff --git a/src/chttpd.erl b/src/chttpd.erl
index c446eac..147415c 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -914,12 +914,14 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, 401=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("application/json") 
of
-                        true ->
+                        case 
MochiReq:accepted_content_types(["application/json", "text/html"]) of
+                        [] ->
                             {Code, []};
-                        false ->
-                            case MochiReq:accepts_content_type("text/html") of
-                            true ->
+                        [Preferred | _] ->
+                            case Preferred of
+                            "application/json" ->
+                                {Code, []};
+                            "text/html" ->
                                 % 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
@@ -934,7 +936,7 @@ error_headers(#httpd{mochi_req=MochiReq}=Req, 401=Code, 
ErrorStr, ReasonStr) ->
                                     "&reason=", 
couch_util:url_encode(ReasonStr)
                                 ]),
                                 {302, [{"Location", absolute_uri(Req, 
RedirectLocation)}]};
-                            false ->
+                            _ ->
                                 {Code, []}
                             end
                         end
{code}

That fixes the authentication_redirect for me, and feels like the right thing 
to do.  With regards to IE8, those Accept headers are complete **llocks, I 
would say not supported, and if you want to support IE8, get behind a reverse 
proxy to do the nasty work for you. -A.

> Improve content type negotiation for couchdb JSON responses
> -----------------------------------------------------------
>
>                 Key: COUCHDB-1175
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-1175
>             Project: CouchDB
>          Issue Type: Improvement
>    Affects Versions: 1.0.2
>            Reporter: Robert Newson
>            Priority: Blocker
>
> Currently we ignore qvalues when negotiation between 'application/json' and 
> 'text/plain' when returning JSON responses.
> Specifically, we test directly for 'application/json' or 'text/plain' in the 
> Accept header. Different branches have different bugs, though. Trunk returns 
> 'application/json' if 'application/json' is present at all, even if it's less 
> preferred than 'text/plain' when qvalues are accounted for.
> We should follow the standard.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to