• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible to determine/set mimetype for CFC-generated content?

Enthusiast ,
Oct 23, 2012 Oct 23, 2012

Copy link to clipboard

Copied

In short, my onCFCRequest() method makes a manual invokation of the component and sends it the arguments.

Let's say, for example, I am calling a component located at www.coms.template

Is it possible for me to do something in a method called in that template component so that when it returns the generated content and we are now back in the onCFCRequest() method, that I can look at the generated content and determine/set/serve the appropriate mimetype?

My methods can generate JSON, WDDX, CSS, Javascript and HTML, and I want to make sure they serve as the appropriate mimetypes when their content is sent to the browser:

  • JSON = text/json
  • WDDX = text/xml
  • Javascript = application/x-javascript
  • CSS = text/css
  • HTML = text/html
  • Other = text/plain

Views

563

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 23, 2012 Oct 23, 2012

Well... you know what content you're generating, so the calling code needn't guess, you can just tell it. Return a struct which has the response data in one key, ans the type in another.

And you set the MIME type for a response using <cfcontent>

--

Adam

Votes

Translate

Translate
LEGEND ,
Oct 23, 2012 Oct 23, 2012

Copy link to clipboard

Copied

Well... you know what content you're generating, so the calling code needn't guess, you can just tell it. Return a struct which has the response data in one key, ans the type in another.

And you set the MIME type for a response using <cfcontent>

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 23, 2012 Oct 23, 2012

Copy link to clipboard

Copied

LATEST

Ah!  Like having the component.cfc set something into the URL scope (like a variable called 'returnType') so that when we get back to the onCFCRequest() it can read the value and say "Oh!  It looks like that component wanted to return it's data as: XML, I'll set the mimetype accordingly.

That makes sense.

** UPDATE ** AND IT WORKS!

Had to do some fannageling, but I got it.  It now properly outputs content in JSON (application/json), WDDX/XML (text/xml), Javascript (application/javascript), CSS (text/css), HTML (text/html) and Text (text/plain).

I did a test and had the component generate HTML code but tell the oCFCR() to serve it up as text and sure enough, it did not evalute the paragraph tags, but displayed them like text.  BRILLIANT!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation