From cf01d7f24d6a57e662cc25d7897f205b1e73b06d Mon Sep 17 00:00:00 2001 From: Bob Date: Tue, 6 Dec 2022 05:01:52 -0500 Subject: [PATCH] #1438: httpkit.client functions (#1439) * expose query-string function from org.httpkit.client * add url-encode from httpkit client ns * cleanup and changelog --- CHANGELOG.md | 3 +++ .../babashka/impl/httpkit_client.clj | 4 +++- test-resources/lib_tests/httpkit/client_test.clj | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fee9ca9..c680d51f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ A preview of the next release can be installed from [Babashka](https://github.com/babashka/babashka): Native, fast starting Clojure interpreter for scripting +## Unreleased +- [#1438](https://github.com/babashka/babashka/issues/1438): expose `query-string` and `url-encode` functions from org.httpkit.client ([@bobisageek](https://github.com/bobisageek)) + ## 1.0.167 (2022-11-30) - [#1433](https://github.com/babashka/babashka/issues/1433): spec source as built-in fallback. When not including the diff --git a/feature-httpkit-client/babashka/impl/httpkit_client.clj b/feature-httpkit-client/babashka/impl/httpkit_client.clj index f51ccaf8..645aaa97 100644 --- a/feature-httpkit-client/babashka/impl/httpkit_client.clj +++ b/feature-httpkit-client/babashka/impl/httpkit_client.clj @@ -72,7 +72,9 @@ 'acl (copy-var acl cns) 'unlock (copy-var unlock cns) 'default-client (copy-var client/default-client cns) - '*default-client* default-client}) + '*default-client* default-client + 'query-string (copy-var client/query-string cns) + 'url-encode (copy-var client/url-encode cns)}) (def sni-client-namespace {'ssl-configurer (copy-var sni-client/ssl-configurer sns) diff --git a/test-resources/lib_tests/httpkit/client_test.clj b/test-resources/lib_tests/httpkit/client_test.clj index 8a15d811..546ff867 100644 --- a/test-resources/lib_tests/httpkit/client_test.clj +++ b/test-resources/lib_tests/httpkit/client_test.clj @@ -58,3 +58,14 @@ (deftest alter-var-root-test (is (alter-var-root (var client/*default-client*) (constantly sni/default-client)))) + +(deftest query-string-test + (is (= (client/query-string {:k1 "v1" :k2 "v2" :k3 nil :k4 ["v4a" "v4b"] :k5 []}) + "k1=v1&k2=v2&k3=&k4=v4a&k4=v4b&k5=")) + (is (= (client/query-string {:k1 \v :k2 'v2}) + "k1=v&k2=v2"))) + +(deftest url-encode-test + (is (= "AbC" (client/url-encode "AbC"))) + (is (= "%3C%3E%21%40%23%24%25%5E" + (client/url-encode "<>!@#$%^"))))