Skip to content

Commit

Permalink
🐛 Fix unexpected rare condition exception on rpc cond middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
niwinz committed Oct 16, 2024
1 parent c841ed6 commit d4c775b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions backend/src/app/rpc/cond.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
(str "W/\"" (encode s) "\""))

(defn wrap
[_ f {:keys [::get-object ::key-fn ::reuse-key?] :as mdata}]
[_ f {:keys [::get-object ::key-fn ::reuse-key?] :or {reuse-key? true} :as mdata}]
(if (and (ifn? get-object) (ifn? key-fn))
(do
(l/trc :hint "instrumenting method" :service (::sv/name mdata))
(fn [cfg {:keys [::key] :as params}]
(if *enabled*
(let [key' (when (or key reuse-key?)
(let [key' (when (or reuse-key? key)
(some->> (get-object cfg params) (key-fn params) (fmt-key)))]
(if (and (some? key) (= key key'))
(fn [_] {::rres/status 304})
(let [result (f cfg params)
etag (or (and reuse-key? key')
(some-> result meta ::key fmt-key)
(some-> result key-fn fmt-key))]
(some->> result meta ::key fmt-key)
(some->> result (key-fn params) fmt-key))]
(rph/with-header result "etag" etag))))
(f cfg params))))
f))

0 comments on commit d4c775b

Please sign in to comment.