Access to Output Buffer

In Adobe CF I used to be able to access the output buffer via GetPageContext().getCFOutput().getBuffer(), but navigating getPageContext() via Dump I can’t find any similar function. I’m sure it’s there somewhere, but I’m not seeing it. I need to access it so that I can do some final processing of the output, reset content, and send out the modified version.

Any thoughts?

I solved it for now with a SaveContent wrapper in Application.cfc, but it would be nice to know if the functions do exist in Lucee.

I’m really not sure what you want to do exactly, and I try to avoid any of those high level functions if possible. E.g. resetting content is as easy as setting content reset = "true";? As I can see from the ACF stuff the .getBuffer() is a function of the class CharBuffer.

Maybe what you want to look at is getPageContext().getResponseStream()?

1 Like

@Ross_Naheedy I think you looking for this is getCharBuffer class in lucee.

3 Likes

CFMitrah,
Thanks. getPageContext().getout().getCharBuffer().toString() is what I needed.

Andreas,
You are correct in that resetting the output via Content Reset=“true” is definitely the way to go for clearing the buffer, but I needed to get the content of the buffer before I cleared it as I need to do some post processing after the page is done and before it’s sent to the browser. More specifically, in my current project, I don’t know what JS libraries I should be including at the top of the page until I’m done with the page. There are a few ways to skin this cat, but the easiest one would be to get the output stream, manipulate it, reset the stream, and then send the new content out. The only caveat is that I can’t do CFFlush anywhere.

Thanks,
Ross.

1 Like

for that use case, I normally just track whatever js / css i want to include in some ordered structs (avoids dups) in the request scope, then I output them at the end.

If you aren’t using a framework which lets you handle this, cfhtmlhead will let you push stuff into the head section of the page (assumes your page has a head tag :wink: )

alternatively, just use a bundler and load your whole js/css eco system once, which will be faster

2 Likes

Didn’t know about CFHTMLHead. That’ll do what I’m trying to do without doing hanky panky with the output stream (although I suspect it works the same way). Thanks!

1 Like