   [[hdrs body] opts]
   [(-> hdrs
        add-xff-header
-       (set-scheme opts)
-       ) body])
+       (set-scheme opts))
+   body])
 
 (defn- proxy-loop?
   [[{[remote-ip] :remote-addr xff-header "x-forwarded-for"}] {cycles :cycles}]

   (addr-from-req req) req opts
   (fn [client-dn]
     (fn [evt val]
       (debug {:msg "Client event"
               :event [evt val]})
       (try
         (cond
          (= :response evt)
          (do
            ;; Because, I think that there might be some crazy race
            ;; condition where the response gets sent before :connected
            ;; TODO: Make sure that this isn't the case.
            (locking req
              (when (= :pending (@state :upstream))
                (downstream :resume nil))
              (swap! state #(assoc % :upstream client-dn :responded? true)))
            (downstream evt val))

          (= :body evt)
          (downstream evt val)

          (= :connected evt)
          (locking req
            (when (= :pending (@state :upstream))
              (downstream :resume nil))
            (swap! state #(assoc % :upstream client-dn)))

          (= :abort evt)
          (do
            (swap! state #(dissoc % :upstream))
            (let [current-state @state]
              (cond
               (bad-gateway? current-state val)
               (downstream :response bad-gateway)

               (service-unavailable? current-state val)
               (downstream :response service-unavailable)

               (gateway-timeout? current-state val)
               (downstream :response gateway-timeout)

               :else
               (downstream evt val))))

          (not= :done evt)
          (downstream evt val))
         (catch Exception e
           (.printStackTrace e))))))

  (when (chunked? req)
    (locking req
      (when-not (@state :upstream)

       (fn [downstream]
         (let [state (atom {})]
           (defstream

             ;; Handling the initial request
             (request [req]
               (debug {:msg "Receiving request" :event [:request req]})

               (if-not (proxy-loop? req opts)
                 ;; not a proxy loop, initiate the request
                 (let [req (process-request req opts)]
                   (initiate-request state opts req downstream))

                 ;; proxy loop, return bad gateway
                 (do
                   (debug {:msg   "In proxy loop" :event [:request req]})
                   (downstream :response bad-gateway))))

             ;; ignore :done events
             (done [])

             ;; all other events go upstream (client's downstream)
             (else [evt val]
               (let [upstream (@state :upstream)]
                 (if (and upstream (not= :pending upstream))
                   (upstream evt val)
                   (throw (Exception. (str "proxy is not expecting message, " [evt val]))))))))))))
