When using Content Negotiation, and the CoerceStupidBrowsers convention,...

... content is negotiated as HTML even when the browser requests json.  This fixes by adding an additional check for json.
We stopped using this feature.. There were some other cases where a
re-fresh sent the incorrect headers, and json was returned, and it also
makes it cumbersome to troubleshoot, in my opinion.

On Fri, Sep 26, 2014 at 12:44 PM, Kristian Hellang <notifications@github.com
> wrote:

> In src/Nancy/Conventions/BuiltInAcceptHeaderCoercions.cs:
>
> > @@ -40,7 +40,18 @@ public static class BuiltInAcceptHeaderCoercions
> >          {
> >              var current = currentAcceptHeaders as Tuple<string, decimal>[] ?? currentAcceptHeaders.ToArray();
> >
> > -            return IsStupidBrowser(current, context) ? DefaultAccept : current;
> > +            return IsNotRequestingJson(current) && IsStupidBrowser(current, context) ? DefaultAccept : current;
> > +        }
> > +
> > +        /// <summary>
> > +        /// Stupid browsers can sometimes send the proper content type, if the browser wants json, we don't
> > +        /// want to send them html.
> > +        /// </summary>
> > +        /// <param name="currentAcceptHeaders">Current Headers</param>
> > +        /// <returns>true if browser is requesting json</returns>
> > +        private static bool IsNotRequestingJson(IEnumerable<Tuple<string, decimal>> currentAcceptHeaders)
> > +        {
> > +            return !(currentAcceptHeaders.Any(header => header.Item1 == "application/json"));
>
> Isn't there a utility method somewhere? Some IsJson method? On the phone
> and too lazy to check [image: :wink:]
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/NancyFx/Nancy/pull/1300/files#r18099535>.
>



-- 
Brendan Tompkins
brendan.tompkins@gmail.com
757-598-1345
757-575-3451 (cell)