Skip to content

Commit

Permalink
[#9] extend proto at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
lispyclouds committed Oct 10, 2023
1 parent 565d9de commit ab42301
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/s_exp/mina/response.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(def ^:no-doc ring-core-loaded
(try
(require '[ring.core.protocols :as p])
(require 'ring.core.protocols)
true
(catch Throwable _ false)))

Expand Down Expand Up @@ -41,9 +41,17 @@

Object
(write-body! [o server-response]
(if (and ring-core-loaded (satisfies? p/StreamableResponseBody o))
(p/write-body-to-stream o nil (.outputStream server-response))
(.send ^ServerResponse server-response o))))
(.send ^ServerResponse server-response o)))

(when ring-core-loaded
(extend-protocol BodyWriter
Object
(write-body! [o server-response]
(let [StreamableResponseBody @(ns-resolve 'ring.core.protocols 'StreamableResponseBody)
write-body-to-stream (ns-resolve 'ring.core.protocols 'write-body-to-stream)]
(if (satisfies? StreamableResponseBody o)
(write-body-to-stream o nil (.outputStream server-response))
(.send ^ServerResponse server-response o))))))

(defn header-name ^HeaderName [ring-header-name]
(HeaderNames/createFromLowercase (name ring-header-name)))
Expand Down

0 comments on commit ab42301

Please sign in to comment.