diff --git a/deps.edn b/deps.edn new file mode 100644 index 00000000..2c567bea --- /dev/null +++ b/deps.edn @@ -0,0 +1,3 @@ +{:paths ["src"] + :deps {org.clojure/clojure {:mvn/version "1.6.0"} + slingshot {:mvn/version "0.12.1"}}} diff --git a/src/clj_http/lite/util.clj b/src/clj_http/lite/util.clj index 5906b05a..a75aa5b3 100644 --- a/src/clj_http/lite/util.clj +++ b/src/clj_http/lite/util.clj @@ -27,10 +27,15 @@ [unencoded] (URLEncoder/encode unencoded "UTF-8")) -(defn base64-encode +(defmacro base64-encode "Encode an array of bytes into a base64 encoded string." [unencoded] - (javax.xml.bind.DatatypeConverter/printBase64Binary unencoded)) + (if (try (import 'javax.xml.bind.DatatypeConverter) + (catch ClassNotFoundException _)) + `(javax.xml.bind.DatatypeConverter/printBase64Binary ~unencoded) + (do + (import 'java.util.Base64) + `(.encodeToString (java.util.Base64/getEncoder) ~unencoded)))) (defn to-byte-array "Returns a byte array for the InputStream provided."