예제 #1
0
void LibEventWorker::doJobImpl(LibEventJobPtr job, bool abort) {
  job->stopTimer();
  evhttp_request *request = job->request;
  assert(m_opaque);
  LibEventServer *server = (LibEventServer*)m_opaque;

  LibEventTransport transport(server, request, m_id);
#ifdef _EVENT_USE_OPENSSL
  if (evhttp_is_connection_ssl(job->request->evcon)) {
    transport.setSSL();
  }
#endif
  bool error = true;
  std::string errorMsg;

  if (abort) {
    transport.sendString("Service Unavailable", 503);
    return;
  }

  try {
    std::string cmd = transport.getCommand();
    cmd = std::string("/") + cmd;
    if (server->shouldHandle(cmd)) {
      transport.onRequestStart(job->getStartTimer());
      m_handler->handleRequest(&transport);
      error = false;
    } else {
      transport.sendString("Not Found", 404);
      return;
    }
  } catch (Exception &e) {
    if (Server::StackTraceOnError) {
      errorMsg = e.what();
    } else {
      errorMsg = e.getMessage();
    }
  } catch (std::exception &e) {
    errorMsg = e.what();
  } catch (...) {
    errorMsg = "(unknown exception)";
  }

  if (error) {
    if (RuntimeOption::ServerErrorMessage) {
      transport.sendString(errorMsg, 500);
    } else {
      transport.sendString(RuntimeOption::FatalErrorMessage, 500);
    }
  }
}
예제 #2
0
void LibEventWorker::doJob(LibEventJobPtr job) {
  job->stopTimer();
  evhttp_request *request = job->request;
  ASSERT(m_opaque);
  LibEventServer *server = (LibEventServer*)m_opaque;

  if (m_handler == NULL) {
    m_handler = server->createRequestHandler();
    ASSERT(m_handler);
  }

  LibEventTransport transport(server, request, m_id);
  bool error = true;
  std::string errorMsg;
  try {
    std::string cmd = transport.getCommand();
    cmd = std::string("/") + cmd;
    if (server->shouldHandle(cmd)) {
      m_handler->handleRequest(&transport);
      error = false;
    } else {
      transport.sendString("Not Found", 404);
      return;
    }
  } catch (Exception &e) {
    if (Server::StackTraceOnError) {
      errorMsg = e.what();
    } else {
      errorMsg = e.getMessage();
    }
  } catch (std::exception &e) {
    errorMsg = e.what();
  } catch (...) {
    errorMsg = "(unknown exception)";
  }

  if (error) {
    if (RuntimeOption::ServerErrorMessage) {
      transport.sendString(errorMsg, 500);
    } else {
      transport.sendString(RuntimeOption::FatalErrorMessage, 500);
    }
  }
}