       (downstream :body (ChannelBuffers/wrappedBuffer GzipUtils/header)))
 
     ;; send the chunks
-    (send-chunks deflater downstream compressed-byte-buffer)
+    (send-chunks deflater downstream buf)
 
     ;; send the trailer if needed
     (when (nil? chunk)


(defn- mk-trailer
  [deflater crc]
  (let [buf (byte-array 8)]
    (GzipUtils/writeTrailer deflater crc buf 0)
    buf))

(defn- gzip-entire-body
  [deflater crc body]
  (let [baos (ByteArrayOutputStream.)
        buf (byte-array 4092)
        bytes (body->byte-array body)]
    ;; write header

  (let [buf-len (alength buf)]
    (loop []
      (let [compressed-bytes (.deflate deflater buf 0 buf-len)]
        (when-not (= 0 compressed-bytes)
          (let [channel-buffer (ChannelBuffers/copiedBuffer buf 0 compressed-bytes)]
            (downstream :body channel-buffer)
            (recur)))))))

(defn- gzip-and-send-chunk
  [state downstream chunk deflater crc buf]
  (let [buffer-length (alength buf)
        sent-header (:sent-header @state)]
    ;; update the crc and set the input
    (if (nil? chunk)
