Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Babashka [http-client](https://github.com/babashka/http-client): HTTP client for Clojure and babashka built on java.net.http

## Unreleased

- [#91](https://github.com/babashka/http-client/issues/91): `decode-body` passes a nil body through, e.g. of a 407 to `CONNECT`

## 0.4.25 (2026-09-11)

- [#86](https://github.com/babashka/http-client/issues/86): `uri-with-query` no longer decodes the existing query, fragment and user info when `:query-params` are used ([@dylanpulver](https://github.com/dylanpulver))
Expand Down
2 changes: 1 addition & 1 deletion src/babashka/http_client/interceptors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
:response (fn [resp]
(let [as (or (-> resp :request :as) :string)
body (:body resp)
body (if (not (string? body))
body (if-not (or (nil? body) (string? body))
(case as
:string (slurp body)
:stream body
Expand Down
21 changes: 21 additions & 0 deletions test/babashka/http_client_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,27 @@
(is (thrown-with-msg? clojure.lang.ExceptionInfo #":host and :port"
(http/->ProxySelector {:host "127.0.0.1"})))))

(deftest proxy-connect-407-test
(let [server (java.net.ServerSocket. 0)
port (.getLocalPort server)]
(future (try (loop []
(with-open [socket (.accept server)]
(let [r (io/reader (.getInputStream socket))
out (io/writer (.getOutputStream socket))]
(dorun (take-while seq (repeatedly #(.readLine r))))
(.write out "HTTP/1.1 407 Proxy Authentication Required\r\nProxy-Authenticate: Basic realm=\"x\"\r\nContent-Length: 0\r\n\r\n")
(.flush out)))
(recur))
(catch Exception _ nil)))
(try
(let [client (http/client {:proxy {:host "127.0.0.1" :port port}})]
(doseq [as [:string :bytes :stream]]
(testing (str "a 407 to CONNECT returns status 407 and a nil body with :as " as)
(let [resp (http/get "https://example.invalid/" {:client client :throw false :as as})]
(is (= 407 (:status resp)))
(is (nil? (:body resp)))))))
(finally (.close server)))))

(deftest cookie-handler-test
(testing "nil passthrough"
(is (nil? (http/->CookieHandler nil))))
Expand Down
Loading