atuttle / Taffy

:candy: The REST Web Service framework for ColdFusion and Lucee
http://taffy.io
Other
225 stars 117 forks source link

ETags not working on Lucee #354

Closed pfreitag closed 5 years ago

pfreitag commented 6 years ago

So, it looks like the code to compute the etag value is simply doing getData().hashCode() where getData() is usually a struct of data. There is an apparent implementation difference in structures between Lucee and ACF such that the following code:

for (i=0;i<5;i++) {
        s = [f:"1"];
        writeOutput(s.hashCode());
        writeOutput("<br>");
}

On Lucee it outputs a different hash code for each iteration, on ACF the same hash code. Because lucee can compute a different hash code for the same data, the etag will never return 304.

Here is a runnable example: https://trycf.com/gist/908dd26c9e074bc2e871b2754339a6f8/lucee5

(found this issue by running the unit tests btw)

I think a better solution might be to perform the hash after serialization because the string will have the same hash code. What do you think?

atuttle commented 6 years ago

Yep, this is a known issue -- at least as far as I've documented it here: http://docs.taffy.io/3.1.0#useetags

NOTE FOR LUCEE USERS: While it will not cause errors, the underlying Java code used in this feature was improperly implemented prior to Lucee 4.0.? and this could result in your result data being sent as if it were changed when it in fact has not. (I'm not sure which Lucee point release will include the fix. The latest as of this writing is version 4.0.2, and does not include it.) Adobe ColdFusion is unaffected.

I remember having some discussions in the Lucee bug tracker asking them to fix it, and they basically ignored me or told me to bugger off or something.

Since the feature is otherwise worthless to Lucee users, I wouldn't be opposed to checking the post-serialization hashcode value if we detect we're on Lucee, but the feature as-is saves ACF users from having to go through the somewhat slow serialization process, so making it a global change would slow them down. (Maybe not? Maybe the java hashCode() will be faster on the serialized string than a large complex object? I haven't measured.) But I would hate for ACF users to have to pay a perf penalty so that Lucee users can get the feature working.

msp1kpj commented 5 years ago

Is there going to be a release update to pull from?