HttpTransact::handle_server_died(State* s)
{
  const char *reason = NULL;
  const char *body_type = "UNKNOWN";
  HTTPStatus status = HTTP_STATUS_BAD_GATEWAY;

  ////////////////////////////////////////////////////////
  // FIX: all the body types below need to be filled in //
  ////////////////////////////////////////////////////////


  //
  // congestion control
  //
  if (s->pCongestionEntry != NULL) {
    s->congestion_congested_or_failed = 1;
    if (s->current.state != CONGEST_CONTROL_CONGESTED_ON_F && s->current.state != CONGEST_CONTROL_CONGESTED_ON_M) {
      s->pCongestionEntry->failed_at(s->current.now);
    }
  }

  switch (s->current.state) {
  case CONNECTION_ALIVE:       /* died while alive for unknown reason */
    ink_release_assert(s->hdr_info.response_error != NO_RESPONSE_HEADER_ERROR);
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Unknown Error";
    body_type = "response#bad_response";
    break;
  case CONNECTION_ERROR:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = (char *) get_error_string(s->cause_of_death_errno);
    body_type = "connect#failed_connect";
    break;
  case OPEN_RAW_ERROR:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Tunnel Connection Failed";
    body_type = "connect#failed_connect";
    break;
  case CONNECTION_CLOSED:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Server Hangup";
    body_type = "connect#hangup";
    break;
  case ACTIVE_TIMEOUT:
    if (s->api_txn_active_timeout_value != -1)
      DebugTxn("http_timeout", "Maximum active time of %d msec exceeded", s->api_txn_active_timeout_value);
    status = HTTP_STATUS_GATEWAY_TIMEOUT;
    reason = "Maximum Transaction Time Exceeded";
    body_type = "timeout#activity";
    break;
  case INACTIVE_TIMEOUT:
    if (s->api_txn_connect_timeout_value != -1)
      DebugTxn("http_timeout", "Maximum connect time of %d msec exceeded", s->api_txn_connect_timeout_value);
    status = HTTP_STATUS_GATEWAY_TIMEOUT;
    reason = "Connection Timed Out";
    body_type = "timeout#inactivity";
    break;
  case PARSE_ERROR:
  case BAD_INCOMING_RESPONSE:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Invalid HTTP Response";
    body_type = "response#bad_response";
    break;
  case CONGEST_CONTROL_CONGESTED_ON_F:
    status = HTTP_STATUS_SERVICE_UNAVAILABLE;
    reason = "Origin server congested";
    if (s->pCongestionEntry)
      body_type = s->pCongestionEntry->getErrorPage();
    else
      body_type = "congestion#retryAfter";
    s->hdr_info.response_error = TOTAL_RESPONSE_ERROR_TYPES;
    break;
  case CONGEST_CONTROL_CONGESTED_ON_M:
    status = HTTP_STATUS_SERVICE_UNAVAILABLE;
    reason = "Too many users";
    if (s->pCongestionEntry)
      body_type = s->pCongestionEntry->getErrorPage();
    else
      body_type = "congestion#retryAfter";
    s->hdr_info.response_error = TOTAL_RESPONSE_ERROR_TYPES;
    break;
  case STATE_UNDEFINED:
  case TRANSACTION_COMPLETE:
  default:                     /* unknown death */
    ink_release_assert(!"[handle_server_died] Unreasonable state - not dead, shouldn't be here");
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = NULL;
    body_type = "response#bad_response";
    break;
  }

  if (s->pCongestionEntry && s->pCongestionEntry->F_congested() && status != HTTP_STATUS_SERVICE_UNAVAILABLE) {
    s->pCongestionEntry->stat_inc_F();
    CONGEST_SUM_GLOBAL_DYN_STAT(congested_on_F_stat, 1);
    status = HTTP_STATUS_SERVICE_UNAVAILABLE;
    reason = "Service Unavailable";
    body_type = s->pCongestionEntry->getErrorPage();
    s->hdr_info.response_error = TOTAL_RESPONSE_ERROR_TYPES;
  }
  ////////////////////////////////////////////////////////
  // FIX: comment stuff above and below here, not clear //
  ////////////////////////////////////////////////////////

  switch (s->hdr_info.response_error) {
  case NON_EXISTANT_RESPONSE_HEADER:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "No Response Header From Server";
    body_type = "response#bad_response";
    break;
  case MISSING_REASON_PHRASE:
  case NO_RESPONSE_HEADER_ERROR:
  case NOT_A_RESPONSE_HEADER:
#ifdef REALLY_NEED_TO_CHECK_DATE_VALIDITY
  case BOGUS_OR_NO_DATE_IN_RESPONSE:
#endif
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Malformed Server Response";
    body_type = "response#bad_response";
    break;
  case MISSING_STATUS_CODE:
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Malformed Server Response Status";
    body_type = "response#bad_response";
    break;
  default:
    break;
  }

  if (reason == NULL) {
    status = HTTP_STATUS_BAD_GATEWAY;
    reason = "Server Connection Failed";
    body_type = "connect#failed_connect";
  }

  build_error_response(s, status, reason, body_type, NULL);

  return;
}