-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bypass fn #24
base: master
Are you sure you want to change the base?
bypass fn #24
Conversation
This is a function that gets called on the response, regardless of whether you're recording or playing back? |
Yes |
hmm; I wonder if this can be more general e.g., an option like: :middleware
(fn [vcr-clj-fn]
(fn [& args]
;; can do something beforehand
(let [res (apply vcr-clj-fn args)]
;; or afterwards with the result
res))) |
Mm, yeah, it's more low-level, but it will cover my needs |
okay, I think I could accept a change like that |
What is the pros of this approach in comparison with |
they're equivalent; the word "middleware" makes me think of ring middleware, which uses the signature I suggested. In contrast, I know robert.hooke uses the signature you mentioned. I don't strongly prefer either. |
I will get to this soon. I've been sick for a week and need to catch up on things. |
@@ -33,7 +35,7 @@ | |||
(if-not (and *recording?* (apply recordable? args*)) | |||
(apply orig-fn args*) | |||
(let [res (binding [*recording?* false] | |||
(return-transformer (apply orig-fn args*))) | |||
(return-transformer (apply (middleware orig-fn) args*))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to preview a response body in a web browser, I'm thinking you'll need the middleware to be applied after the return-transformer
so that the body has already been made re-readable, does that sound right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having the middleware see the transformed return value should also make it more consistent with the way it's called during playback.
:or {arg-transformer vector | ||
arg-key-fn vector | ||
recordable? (constantly true) | ||
middleware (fn [f] | ||
(fn [& args] (apply f args))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be simplified to identity
(let [k (apply arg-key-fn args*) | ||
res (:return (the-playbacker the-var-name k))] | ||
(apply (middleware (fn [& args] res)) args*)) | ||
(apply (middleware orig) args*))))]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I would expect the middleware
to be called in the non-recordable case; what do you think?
(apply orig args*))))]] | ||
(let [k (apply arg-key-fn args*) | ||
res (:return (the-playbacker the-var-name k))] | ||
(apply (middleware (fn [& args] res)) args*)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the middleware could be applied to the real playback function rather than an artificial function via something like
(apply (middleware (fn [& args] (:return (the-playbacker the-var-name (apply arg-key-fn args))))))
(args-test args) | ||
(let [res (apply vcr-clj-fn args)] | ||
(res-test res) | ||
res))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you either move these defn
s to the top level or transform them into a let
or letfn
? I don't think nested def
s are idiomatic in clojure.
Hi, this is a bypass function implementation. My use case is open clj-http request results in browser for manual verification.