 
 (defn- gzip-entire-body
   [deflater crc body]
-  (println "GZIPPING ENTIRE BODY")
   (let [baos (ByteArrayOutputStream.)
         buf (byte-array 4092)
         bytes (body->byte-array body)]

          (do
            (.write baos (mk-trailer deflater crc))
            (.close baos)
            (let [channel-buffer (ChannelBuffers/copiedBuffer (.toByteArray baos))]
              channel-buffer)))))))

(defn- send-chunks
  [deflater downstream buf]
  (println "GZIPPING CHUNKS")
  (let [buf-len (alength buf)]
    (loop []
      (let [compressed-bytes (.deflate deflater buf 0 buf-len)]
        (if-not (= 0 compressed-bytes)
          (let [channel-buffer (ChannelBuffers/copiedBuffer buf 0 compressed-bytes)]
            (println "channel buffer: ")
            (println (ChannelBuffers/hexDump channel-buffer))
            (downstream :body channel-buffer)
            (recur)))))))


             (.reset deflater)

             ;; send the resposne with appropriate headers
             (let [content-type-header (content-type hdrs)
                   gzip-content-type? (contains? (:gzip-content-types opts) content-type-header)]
               (if-not (and gzip-content-type? (:accept-gzip? @state))
                 (downstream :response resp)
                 (let [hdrs (assoc hdrs "content-encoding" "gzip")]
                   (swap! state #(assoc % :gzip? true))
                   (if (= :chunked body)
                     (let [hdrs (-> hdrs (assoc "transfer-encoding" "chunked") (dissoc "content-length"))]
                       (downstream :response [status hdrs body]))
                     (let [gzipped-body (gzip-entire-body deflater crc body)
                           hdrs (assoc hdrs "content-length" (.readableBytes gzipped-body))]
                       (downstream :response [status hdrs gzipped-body])))))))

           (body [chunk]
             (if-not (:gzip? @state)
