             [catacumba.stream :as stream]
             [catacumba.utils :as utils]
             [catacumba.impl.context :as ctx]
-            [catacumba.impl.helpers :as helpers]
+            [catacumba.impl.helpers :as ch]
             [catacumba.impl.http :as http])
   (:import ratpack.handling.Handler
            ratpack.handling.Context

    (let [metadata (meta handler)]
      (:handler-type metadata)))
  :default :catacumba/default)

(defmethod adapter :catacumba/default
  [handler]

  InputStream
  (send [data ^Context ctx]
    (let [^Response response (.getResponse ctx)
          ^Promise prom (ch/blocking
                         (let [^bytes buffer (byte-array 1024)
                               ^ByteBuf buf (Unpooled/buffer (.available data))]
                           (loop [index 0]
                             (let [readed (.read data buffer 0 1024)]
                               (when-not (= readed -1)
                                 (.writeBytes buf buffer 0 readed)
                                 (recur (+ index readed)))))
                           buf))]
      (ch/then prom (fn [buff]
                      (.send response buff))))))

(extend-protocol IResponse
  DefaultContext
