I'm using version 1.9.0.4, but also tried with svn-trunk.. and in the
end it doesn't matter.
The whole HTTP-Header handling in MachII looks ambiguous to me.

In your example, the http header is set with the method
"addHTTPHeaderByName".
What "addHTTPHeaderByName" in the end does is the following:

<cfheader name="#arguments.name#" value="#arguments.value#"
charset="#arguments.charset#" />

So, MachII framework passes the charset-declaration via the charset
attribute.
It never appends the charset-declaration to the value attribute.
The problem is, this doesn't really insert the charset-declaration
into the http header, it just defines the encoding of the actual
header value (you'll find out, if you use a network sniffer like
wireshark).

Adobe docs about the charset attribute:
"The character encoding in which to encode the header value."
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7aea.html

What i need is:
<cfheader name="content-type" value="application/json; charset=utf-8"
charset="utf-8" />

What MachII does is:
<cfheader name="content-type" value="application/json"
charset="utf-8" />

Thanks for help.


On 17 Mrz., 21:53, "Peter J. Farrell" <[email protected]> wrote:
> What version of 1.9 are you using?  Be sure to use a nightly zip or a
> checkout from SVN as a lot has changed in the REST stuff since the M1
> release.
>
> By default, the content-type header is send my the base REST endpoint
> for you based the file extension in the url (in your case .json) or the
> file type in the defaultFormat parameter you set in endpoint config XML.
>
> Here is what the code looks like behind the scenes.  As you can see, we
> use the value you set in the defaultCharset parameter when we set the
> header:
>
>     <cffunction name="addContentTypeHeaderFromFormat" access="private"
> returntype="void" output="false"
>         hint="Adds a Content-Type response header based on the input
> format.">
>         <cfargument name="format" type="string" required="true"
>             hint="The incoming format type to add as header." />
>
>         <cfset var contentType = "" />
>
>         <cftry>
>             <!--- Leverage this nicely provided utility method and no
> need to prefix with '.' when using 'evaluateAllAsFileExtensions' set to
> true --->
>             <cfset contentType =
> getUtils().getMimeTypeByFileExtension(arguments.format,
> variables.customMimeTypeMap, true) />
>
>             <!--- Add the Content-Type header --->
>             <cfset addHTTPHeaderByName("Content-Type", contentType,
> getDefaultCharset()) />
>
>             <cfcatch type="any">
>                 <!--- Log exception --->
>                 <cfset
> getLog().error("MachII.endpoints.rest.BaseEndpoint: Could not find
> Content-Type for input format: '#arguments.format#'.", cfcatch) />
>             </cfcatch>
>         </cftry>
>     </cffunction>
>
> > Hey
>
> > If i want to get JSON-Data from an RestEndpoint, i need to declare the
> > content-type (including the charset) for my response ("Content-Type:
> > application/json; charset=utf-8"). Otherwise the data would be
> > displayed wrong on my utf-8 based JS-Client.
>
> > With the actual defaultCharset property in the config-xml, i do not
> > set this charset attribute in the Content-Type-HTTP-Header value, but
> > only the encoding of the header value itself (http://help.adobe.com/
> > en_US/ColdFusion/9.0/CFMLRef/
> > WSc3ff6d0ea77859461172e0811cbec22c24-7aea.html).
>
> > Do you have any suggestions, what's best practice to set the charset
> > attribute in the HTTP-Header-Value called "Content-Type"?
>
> > Cheers,
>
> > delijah
>
>

-- 
To post to this group, send email to [email protected]
For more options and to unsubscribe, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to