clj-http-fake icon indicating copy to clipboard operation
clj-http-fake copied to clipboard

Supporting async requests from clj-http.

Open dixel opened this issue 6 years ago • 4 comments

Hi! Would be nice to add support for async requests from clj-http. It requires some additions to the API that could be a bit challenging but still useful in asynchronous scenarios. In my use-case it can improve things a lot in terms of tests backward-compatibility while moving certain parts of the application to clj-http/3.x and async requests.

dixel avatar Jan 23 '18 14:01 dixel

Hi. You can make a pull request for this :) I haven't touched anything clojure related in years.

valpackett avatar Jan 23 '18 15:01 valpackett

@dixel did you find a workaround for this? I’m looking for a solution to mock async requests for clj-http.

bfontaine avatar Sep 02 '19 12:09 bfontaine

@bfontaine not really. So far with-redefs does quite a good job most of the time.

dixel avatar Sep 02 '19 22:09 dixel

Unless I’m missing something, if you use the response/raise callbacks, using clj-http-fake with :async? requests is perfectly fine:

(with-fake-routes-in-isolation {"http://foo" (fn [_] {:status 201 :headers {}})}
  (http/get "http://foo"
    {:async? true}
    (fn [a] (println "OK" a))
    (fn [b] (println "NOPE" b))))

;; prints:
;; OK {:status 200, :body , :headers {}, :request-time 0, :orig-content-encoding nil}

It doesn’t work only if you rely on the FutureWrapper returned by clj-http.

bfontaine avatar Sep 05 '19 18:09 bfontaine

I ran into this issue the other day. Since this has been pending for a while I wrote up a PR and submitted it for review.

tcushman avatar Feb 23 '23 18:02 tcushman

I ran into this issue the other day. Since this has been pending for a while I wrote up a PR and submitted it for review.

Would it be possible to build a new release that contains this fix?

tcushman avatar Mar 01 '23 19:03 tcushman

Yeah.. um, would you like to do it? :) I don't feel like installing the whole clojure stuff just for this, but I probably can add you as a collaborator here and on clojars

valpackett avatar Mar 01 '23 19:03 valpackett