Saturday 19 January 2013

ColdFusion: 2 - Cameron: nil

G'day:
You know how I say I like being wrong? Well it's a good thing I like it as I get a lot of practise at it.

14 June 2013

I've just updated the score to be 2-0 because this very same problem just caught me out again, and when googling for the answer, came across this very blog post. Sigh. God I'm thick.




A week or so ago I lamented some odd behaviour with CFHTTP when it comes to JSON. If the MIME type was application/json, then the JSON was returned as a ByteArrayOutputStream rather than a string, despite the fact JSON is obviously a string.

Well had I RTFMed as one of my commenters pointed out (they were more polite than I am being), I would have noticed this:


AttributegetAsBinary
Req/OptOptional
Defaultno
Description
no
if ColdFusion does not recognize the response body type as text, converts it to a ColdFusion object.
auto
if ColdFusion does not recognize the response body type as text, converts it to ColdFusion Binary type data.
yes
always converts the response body content into ColdFusion Binary type data, even if ColdFusion recognizes the response body type as text.
never
prevents the automatic conversion of certain MIME types to the ColdFusion Binary type data; treats the returned content as text.
ColdFusion recognizes the response body as text if:
  • the header does not specify a content type.
  • the content type starts with "text".
  • the content type starts with "message".
  • the content type is "application/octet-stream".
If ColdFusion does not recognize the body as text and converts it to an object, but the body consists of text, the cfoutput tag can display it. The cfoutput tag cannot display Binary type data. (To convert binary data to text, use the ToString function.)

(that's from the <cfhttp> docs).

Now - to be frank - as everyone knows "no means no", so I really don't think Adobe is being very enlightened here to use a different definition of "no" which means "actually sometimes yes", but still... had I RTFMed I would have actually noticed that getasbinary="never" does precisely what I want it to do.

I checked on CF9.0.2, 10.0.7 and Railo 4.0.2, and all behave the same.

--
Adam