                (swap! state #(assoc % :upstream next-up))
                (next-up evt val)))
 
+           (= :close evt)
+           (when next-up
+             (throw (IOException. "Connection reset by peer")))
+
            next-up
            (next-up evt val)
 
-           :else
+           (not (#{:open :close} evt))
            (throw (Exception. "Not expecting a message right now."))))))))

 awaiting-100-continue
 waiting-for-response)

(defrecord ExchangeState
    [connection
     next-up-fn
     next-dn-fn
     keepalive?

(ns picard.http.server
  (:use picard.http.core))

;; TODO:
;; * Count the bytes in the request body

(declare
 handle-request
