From 2b8ca233de503d007e88643d763ed55e094eb003 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 18 Apr 2024 16:45:56 +0200 Subject: [PATCH] Testing interceptors --- CHANGELOG.md | 4 ++++ README.md | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa8bbef..d5fc456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Babashka [http-client](https://github.com/babashka/http-client): HTTP client for Clojure and babashka built on java.net.http +## 0.4.18 (2024-04-18) + +- Support a Clojure function as `:client` option, mostly useful for testing + ## 0.4.17 (2024-04-12) - [#49](https://github.com/babashka/http-client/issues/49): add `::oauth-token` interceptor diff --git a/README.md b/README.md index c193828..ca31023 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,17 @@ function is executed on the response. Default interceptors are in configured on the level of requests by passing a modified `:interceptors` chain. +#### Testing interceptors + +For testing interceptors it can be useful to use the `:client` option in combination with a +Clojure function. When passing a function, the request won't be converted to a +`java.net.http.Request` but just passed as a ring request to the function. The +function is expected to return a ring response: + +``` clojure +(http/get "https://clojure.org" {:client (fn [req] {:body 200})}) +``` + ### Async To execute request asynchronously, use `:async true`. The response will be a @@ -375,7 +386,7 @@ Here is a code snippet for `deps.edn` {:jvm-opts [;; enable logging for java.net.http "-Djdk.httpclient.HttpClient.log=errors,requests,headers,frames[:control:data:window:all..],content,ssl,trace,channel"]} -}} +}} ``` ## Test