Best way to handle etag (for HTTP caching) in a Ring app
Is there an accepted good way to gandle HTTP etags in a ring app? Some googling turned up this, which appears to be the best publicly available library:
https://github.com/mikejs/ring-etag-middleware
However, the predicate it uses for determining if a request body is suitable for an ETag is this:
(if (or (string? body) (instance? body File))
I don't basically ever use instance?, but those arguments look backward... which would mean that this library has only worked for strings in the eight years since it was last modified. I'm hoping there's something obviously wrong with my understanding here, because I am getting the error I'd expect from those parameters being reversed:
2018-10-17 20:51:07,757 [qtp1081313350-11] WARN org.eclipse.jetty.server.HttpChannel - /0.1.4-SNAPSHOT/highlight.pack.js
java.lang.ClassCastException: sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream cannot be cast to java.lang.Class
at clojure.core$instance_QMARK___5126.invokeStatic(core.clj:144)
at clojure.core$instance_QMARK___5126.invoke(core.clj:144)
at ring.middleware.etag$wrap_etag$fn__4389.invoke(etag.clj:37)
...
FWIW, this is the etag middleware suggested here: https://github.com/ring-clojure/ring/wiki/Third-Party-Libraries
Posted Oct 18, 2018, 1:47 AM UTC
I'm using ring-etag-middleware by Daniel Compton. It only adds etags for
Fileresponses, but at least it works correctly.Thanks!