anchor.diff:       host
        (when content-length (parse-integer content-length)))))
   
  +(defun forward-bytes (from to &key how-many)
  +  (let ((buffer (make-array (min (or how-many 2048) 2048)
  +                            :element-type '(unsigned-byte 8)))
  +        (so-far 0))
  +    (loop for n = (read-sequence buffer from) do
  +         (when (= 0 n) (loop-finish))
  +         (write-sequence buffer to :end n)
  +         (when (and how-many (<= how-many (incf so-far n))) (loop-finish)))
  +    (force-output to)))
  +
   (defun forward-response (hosts-table browser-stream forward-headers host
  -                         content-length)
  -  (declare (ignore content-length)) ;; for now
  +                         content-length server-timeout)
     (let ((server (cdr (or (assoc host hosts-table :test #'string=)
                            (car hosts-table)))))
       (with-client-socket (server-socket server-stream (car server) (cadr server)
                                          :element-type '(unsigned-byte 8))
  -      (set-timeout server-socket 2)
  +      (set-timeout server-socket server-timeout)
         (let ((s (make-flexi-stream server-stream :external-format :latin1)))
  -        (princ forward-headers s)
  -        (crlf s)
  -        (finish-output s))
  -      (let ((buffer (make-array 2048 :element-type '(unsigned-byte 8))))
  -        (loop for n = (read-sequence buffer server-stream) while (< 0 n)
  -           do (write-sequence buffer browser-stream :end n)
  -           finally (force-output browser-stream))))))
  +        (princ forward-headers s) (crlf s) (finish-output s))
  +      (when content-length
  +        (forward-bytes browser-stream server-stream :how-many content-length))
  +      (forward-bytes server-stream browser-stream))))
   
  -(defun proxy-connection (browser-socket hosts-table)
  -  (set-timeout browser-socket 2)
  +(defun proxy-connection (browser-socket hosts-table client-timeout server-timeout)
  +  (set-timeout browser-socket client-timeout)
     (multiple-value-call #'forward-response
       hosts-table
       (socket-stream browser-socket)
  
positive.code:       (socket-stream browser-socket)
        :external-format (make-external-format :latin1 :eol-style :crlf))
       (usocket::host-to-hostname (get-peer-address browser-socket))
       (usocket::host-to-hostname (get-local-address browser-socket)))))
  
  (defun start-proxy (port hosts-table)
    "Start a reverse HTTP proxy on the specified port. hosts-table
  should consist of a list of hosts to be forwarded to particular IPs
  and ports, like so: ((domain1 127.0.0.1 8080) (domain2 127.0.0.1 8081))
  
  Returns the main proxy server thread."
    (bt:make-thread
     (lambda ()
       (with-server-socket (listener (socket-listen
  
negative.code:               (let ((socket (socket-accept listener)))
                  (bt:make-thread
                   (lambda ()
                     (handler-case
                         (with-connected-socket (socket socket)
                           (proxy-connection socket hosts-table
                                             client-timeout server-timeout))
                       (error ())))
                   :name (format nil "simple-vhost-proxy (port ~A) connection thread"
                                 port)))
  