Merge pull request #10006 from Icinga/http-error-handling

HttpServerConnection: use exceptions for error handling
This commit is contained in:
Julian Brost 2024-03-08 15:06:51 +01:00 committed by GitHub
commit af97431bfb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -190,10 +190,8 @@ bool EnsureValidHeaders(
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return false; return false;
} }
@ -215,10 +213,8 @@ void HandleExpect100(
response.result(http::status::continue_); response.result(http::status::continue_);
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
} }
} }
@ -257,10 +253,8 @@ bool HandleAccessControl(
response.content_length(response.body().size()); response.content_length(response.body().size());
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return false; return false;
} }
@ -288,10 +282,8 @@ bool EnsureAcceptHeader(
response.content_length(response.body().size()); response.content_length(response.body().size());
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return false; return false;
} }
@ -329,10 +321,8 @@ bool EnsureAuthenticatedUser(
response.content_length(response.body().size()); response.content_length(response.body().size());
} }
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return false; return false;
} }
@ -423,8 +413,8 @@ bool EnsureValidBody(
response.set(http::field::connection, "close"); response.set(http::field::connection, "close");
http::async_write(stream, response, yc[ec]); http::async_write(stream, response, yc);
stream.async_flush(yc[ec]); stream.async_flush(yc);
return false; return false;
} }
@ -464,10 +454,8 @@ bool ProcessRequest(
HttpUtility::SendJsonError(response, nullptr, 500, "Unhandled exception" , DiagnosticInformation(ex)); HttpUtility::SendJsonError(response, nullptr, 500, "Unhandled exception" , DiagnosticInformation(ex));
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return true; return true;
} }
@ -476,10 +464,8 @@ bool ProcessRequest(
return false; return false;
} }
boost::system::error_code ec; http::async_write(stream, response, yc);
stream.async_flush(yc);
http::async_write(stream, response, yc[ec]);
stream.async_flush(yc[ec]);
return true; return true;
} }
@ -574,8 +560,8 @@ void HttpServerConnection::ProcessMessages(boost::asio::yield_context yc)
} }
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
if (!m_ShuttingDown) { if (!m_ShuttingDown) {
Log(LogCritical, "HttpServerConnection") Log(LogWarning, "HttpServerConnection")
<< "Unhandled exception while processing HTTP request: " << ex.what(); << "Exception while processing HTTP request from " << m_PeerAddress << ": " << ex.what();
} }
} }