atuttle / Taffy

:candy: The REST Web Service framework for ColdFusion and Lucee
http://taffy.io
Other
226 stars 117 forks source link

DefaultMime not working with Chrome, Microsoft Edge or Firefox address bar requests #441

Open JamoCA opened 4 months ago

JamoCA commented 4 months ago

I configured the application's defaultMime to be json. The customSerializer.cfc is configured with getAsJson as default, but it doesn't seem to be working

Chromium appears to be using the following as the request Accept header rather than something generic like "/". (I'm testing using Microsoft EdgeDev with a work profile.)

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7

Firefox 125.0.1 uses the following Accept header:

text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8

I've updated core.buildRequestArguments() to check for overloading of the Accept header to return defaultMime when both text/html and image/ are used so that the configured default mime works.

<cfelseif structKeyExists(arguments.headers, "Accept") && findnocase("text/html", arguments.headers.accept) && findnocase("image/", arguments.headers.accept)>
    <cfset local.returnData["_taffy_mime"] = application._taffy.settings.defaultMime>
<cfelseif structKeyExists(arguments.headers, "Accept")>...

Is this a good approach? I don't believe that explicit API requests for XML will use an Accept header that includes both text/html and image/, but I could be wrong.