Fix four HTTP proxying problems.

* Added "Connection: close" to 5xx errors.
* Properly close both upstream and downstream connections on errors.
* Fixed infinite loop when responding to HEAD requests that have no body.
* Fixed randomness when using keep-alive connections. Previously, the behavior
  was only randomly selected on new connections, but HTTP keep-alive connections
  need to choose a random behavior for each new request/response.