(def handle-request-thread (i o ip)
  (with (nls 0 lines nil line nil responded nil)
    (after
      (whilet c (unless responded (readc i))
        (if srv-noisy* (pr c))
        (if (is c #\newline)
            (if (is (++ nls) 2) 
                (let (type op args n cooks) (parseheader (rev lines))
                  (srvlog 'srv ip type op cooks)
                  (case type
                    get  (respond o op args cooks ip)
                    post (handle-post i o op n cooks ip)
                         (respond-err o "Unknown request: " (car lines)))
                  (assert responded))
                (do (push (string (rev line)) lines)
                    (wipe line)))
            (unless (is c #\return)
              (push c line)
              (= nls 0))))
      (close i o)))
  (harvest-fnids))

From srv.arc ©