Skip to content

Commit

Permalink
Move byte array impl of StreamableResponseBody
Browse files Browse the repository at this point in the history
The extend-protocol macro doesn't officially support non-symbol types,
such as (Class/forName "[B"). The implementation of
StreamableResponseBody for byte arrays is therefore moved out to the
low-level extend function.
  • Loading branch information
weavejester committed Oct 19, 2024
1 parent d7d0378 commit 15563cc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ring-core-protocols/src/ring/core/protocols.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
(io/writer output-stream :encoding charset)
(io/writer output-stream)))

;; Extending primitive arrays prior to Clojure 1.12 requires using the low-level
;; extend function.
(extend (Class/forName "[B")
StreamableResponseBody
{:write-body-to-stream
(fn [body _ ^OutputStream output-stream]
(.write output-stream ^bytes body)
(.close output-stream))})

(extend-protocol StreamableResponseBody
#_{:clj-kondo/ignore [:syntax]} (Class/forName "[B")
(write-body-to-stream [body _ ^OutputStream output-stream]
(.write output-stream ^bytes body)
(.close output-stream))
String
(write-body-to-stream [body response output-stream]
(doto (response-writer response output-stream)
Expand Down

0 comments on commit 15563cc

Please sign in to comment.