             [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

  InputStream
  (send [data ^Context ctx]
    (let [^Response response (.getResponse ctx)
          ^Promise prom (.blocking ctx #(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))]
      (.then prom (helpers/action
                   (fn [buff]
                     (.send response buff)))))))

(extend-protocol IResponse
  DefaultContext


  Request
  (get-body* [^Request request]
    (Blocking/on (.getBody request))))

(extend-protocol IHeaders
  DefaultContext
