clojure.java.io/copy + registry-aware io/as-url

clj-http-lite drives bytes through clojure.java.io/copy (response body into a
ByteArrayOutputStream, request body out) and resolves URLs via io/as-url. Neither
worked for a library shim:

- io/copy was absent. Add it: raw bytes / string / a jhost reader write in one
  shot; any other source drains via .read into a buffer and .write to the dest,
  both through method dispatch — so a library's tagged-table streams copy without
  the host knowing their layout.
- io/as-url ignored a library-registered URL class, so it and (URL. spec)
  disagreed (the file-only jhost has no getProtocol/getHost/...). It now honors a
  registered URL ctor, falling back to the jhost.

Runtime .ss shims, no re-mint.
This commit is contained in:
Yogthos 2026-06-22 13:34:19 -04:00
parent 3253df979a
commit 5bcfc629fc
2 changed files with 34 additions and 1 deletions

View file

@ -284,4 +284,11 @@
((file-exists? (string-append (car roots) "/" nm)) (make-jfile (string-append (car roots) "/" nm)))
(else (loop (cdr roots)))))))
(def-var! "clojure.java.io" "resource" jolt-io-resource)
(def-var! "clojure.java.io" "as-url" (lambda (x) (if (and (jhost? x) (string=? (jhost-tag x) "url")) x (make-url (jolt-str-render-one x)))))
;; as-url honors a library-registered URL class (e.g. jolt-lang/http-client's full
;; java.net.URL shim) so io/as-url and (URL. spec) agree; else the file-only jhost.
(def-var! "clojure.java.io" "as-url"
(lambda (x)
(cond ((and (jhost? x) (string=? (jhost-tag x) "url")) x)
((htable? x) x)
(else (let ((ctor (lookup-class class-ctors-tbl "URL")))
(if ctor (ctor (jolt-str-render-one x)) (make-url (jolt-str-render-one x))))))))