Setting etags with Lucee

I’m trying to manually calculate etag hashes and send headers using code I’m pulling off an Adobe CF server. Everything has gone smoothly enough except this.

The crux of my problem is that I need the content of the current page after all processing as a string. I hash it and go from there. With Adobe I used getPageContext().getCFOutput().getString(). On Lucee, I can’t find the equivalent (after lots of guessing through the getPageContext() dumps).

Can someone translate those functions to ones that exist in Lucee? Or am I reinventing a wheel that Lucee has built-in with some nifty command or administrator setting? I’m open to being guided to a better way to trap this mouse.

Many thanks ahead of time for educating me on this.

This is for static content or dynamic content?

Dynamic. Headers and footers included conditionally, database loops, etc. So I have to get the page’s content after evaluation of all parts.

Then are you sure that you want to use caching?

It seems like you will have to generate the content anyway in order to calculate the hash, so what’s the benefit with caching?

Caching is useful when you know at the beginning of the request that you don’t need to process it, thus saving the processing time. If you are processing it anyway then where’s the benefit?

Or am I missing something?

Etags are about saving bandwidth, not CPU cycles. In fact, that’s pretty much their primary purpose - to sensibly cache dynamic pages so that data that changes without a schedule can still send a 304 until there is something new to display to the user. They also work for “static” pages for which changes need to be immediately visible, which really means they’re not truly static, but that’s just semantics.

So yes, I am certain that I want to use etags. I am not certain how to convert my Adobe CF code to Lucee CF code. I have scoured the Internet to the best of my ability but I haven’t seen anyone run into the same problem, which makes me wonder if Lucee has a checkbox somewhere that does all the etag handling for you. Or maybe there’s a much simpler way to get a hash of the page content?

Hi.

I just searched and tested a bit and I#m not sure if, that’s what you need. But i came across

GetPageContext().getout().getString()

and it looks, that all generated source is available in that function.

Regards
Michael

1 Like

That’s it, thank you. I’m not sure why I didn’t see that when I was combing through the GetPageContext() methods, but I’m grateful you caught it.

Now, to figure out how to get Lucee to pass request headers when used as an Apache proxy. Sigh.

Hi Sean,

although I’m running NGinx, is that the part you are looking for?

StructKeyExists(GetHttpRequestData().headers, "If-None-Match") and len(lcase(GetHttpRequestData().headers["If-None-Match"]))

or this?

<cfheader name="ETag" value="w/""#sEtag#""">

Regards
Michael