Repository: oatpp/oatpp
File: src/oatpp/web/server/HttpProcessor.cpp (C++)

Code before:
                                                                 headersReadResult.startingLine,
                                                                 route.matchMap,
                                                                 headersReadResult.headers,
                                                                 resources.inStream,
                                                                 resources.components->bodyDecoder);

  std::shared_ptr<protocol::http::outgoing::Response> response;

  try{

    auto currInterceptor = resources.components->requestInterceptors->getFirstNode();
    while (currInterceptor != nullptr) {
      response = currInterceptor->getData()->intercept(request);
      if(response) {
        break;
      }
      currInterceptor = currInterceptor->getNext();
    }

    if(!response) {
      response = route.getEndpoint()->handle(request);
    }

  } catch (oatpp::web::protocol::http::HttpError& error) {

    auto response1 = resources.components->errorHandler->handleError(error.getInfo().status, error.getMessage(), error.getHeaders());
    response1->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;

  } catch (std::exception& error) {

    auto response1 = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, error.what());
    response1->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;

  } catch (...) {
    auto response1 = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, "Unknown error");
    response1->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;
  }

  response->putHeaderIfNotExists(protocol::http::Header::SERVER, protocol::http::Header::Value::SERVER);
  auto connectionState = protocol::http::utils::CommunicationUtils::considerConnectionState(request, response);

  auto contentEncoderProvider =
    protocol::http::utils::CommunicationUtils::selectEncoder(request, resources.components->contentEncodingProviders);

  response->send(resources.connection.get(), &resources.headersOutBuffer, contentEncoderProvider.get());

  switch(connectionState) {


Review comment (suggestion):
Maybe, let's just reuse the `response` variable declared before the `try` block.
just to avoid the `..1` vars.


Code after:
                                                                 headersReadResult.startingLine,
                                                                 route.matchMap,
                                                                 headersReadResult.headers,
                                                                 resources.inStream,
                                                                 resources.components->bodyDecoder);

  std::shared_ptr<protocol::http::outgoing::Response> response;

  try{

    auto currInterceptor = resources.components->requestInterceptors->getFirstNode();
    while (currInterceptor != nullptr) {
      response = currInterceptor->getData()->intercept(request);
      if(response) {
        break;
      }
      currInterceptor = currInterceptor->getNext();
    }

    if(!response) {
      response = route.getEndpoint()->handle(request);
    }

  } catch (oatpp::web::protocol::http::HttpError& error) {

    response = resources.components->errorHandler->handleError(error.getInfo().status, error.getMessage(), error.getHeaders());
    response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;

  } catch (std::exception& error) {

    response = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, error.what());
    response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;

  } catch (...) {
    response = resources.components->errorHandler->handleError(protocol::http::Status::CODE_500, "Unknown error");
    response->send(resources.connection.get(), &resources.headersOutBuffer, nullptr);
    return false;
  }

  response->putHeaderIfNotExists(protocol::http::Header::SERVER, protocol::http::Header::Value::SERVER);
  auto connectionState = protocol::http::utils::CommunicationUtils::considerConnectionState(request, response);

  auto contentEncoderProvider =
    protocol::http::utils::CommunicationUtils::selectEncoder(request, resources.components->contentEncodingProviders);

  response->send(resources.connection.get(), &resources.headersOutBuffer, contentEncoderProvider.get());

  switch(connectionState) {