Skip to content

Commit 15563cc

Browse files
committed
Move byte array impl of StreamableResponseBody
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.
1 parent d7d0378 commit 15563cc

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ring-core-protocols/src/ring/core/protocols.clj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@
3636
(io/writer output-stream :encoding charset)
3737
(io/writer output-stream)))
3838

39+
;; Extending primitive arrays prior to Clojure 1.12 requires using the low-level
40+
;; extend function.
41+
(extend (Class/forName "[B")
42+
StreamableResponseBody
43+
{:write-body-to-stream
44+
(fn [body _ ^OutputStream output-stream]
45+
(.write output-stream ^bytes body)
46+
(.close output-stream))})
47+
3948
(extend-protocol StreamableResponseBody
40-
#_{:clj-kondo/ignore [:syntax]} (Class/forName "[B")
41-
(write-body-to-stream [body _ ^OutputStream output-stream]
42-
(.write output-stream ^bytes body)
43-
(.close output-stream))
4449
String
4550
(write-body-to-stream [body response output-stream]
4651
(doto (response-writer response output-stream)

0 commit comments

Comments
 (0)