aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/servers/httpparser.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2023-10-20 14:44:53 +0200
committerGitHub <[email protected]>2023-10-20 14:44:53 +0200
commit9a1425265a1d518aaf87cde01f9aef741a609b2d (patch)
treeff6f4cabdb59cec3509ba1ccabe3afbb461c0f48 /src/zenhttp/servers/httpparser.cpp
parentplace tests in own group (for sln) (#488) (diff)
downloadzen-9a1425265a1d518aaf87cde01f9aef741a609b2d.tar.xz
zen-9a1425265a1d518aaf87cde01f9aef741a609b2d.zip
improve error handling when parsing http requests (#489)
* catch exceptions in HttpRequestParser::OnMessageComplete() callback
Diffstat (limited to 'src/zenhttp/servers/httpparser.cpp')
-rw-r--r--src/zenhttp/servers/httpparser.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/zenhttp/servers/httpparser.cpp b/src/zenhttp/servers/httpparser.cpp
index 6b987151a..c64134c95 100644
--- a/src/zenhttp/servers/httpparser.cpp
+++ b/src/zenhttp/servers/httpparser.cpp
@@ -2,6 +2,7 @@
#include "httpparser.h"
+#include <zencore/except.h>
#include <zencore/logging.h>
#include <zencore/string.h>
@@ -62,7 +63,6 @@ HttpRequestParser::ConsumeData(const char* InputData, size_t DataSize)
ZEN_WARN("HTTP parser error {} ('{}'). Closing connection", http_errno_name(HttpErrno), http_errno_description(HttpErrno));
return ~0ull;
}
-
return ConsumedBytes;
}
@@ -360,11 +360,41 @@ HttpRequestParser::OnMessageBegin()
int
HttpRequestParser::OnMessageComplete()
{
- m_Connection.HandleRequest();
-
- ResetState();
-
- return 0;
+ try
+ {
+ m_Connection.HandleRequest();
+ ResetState();
+ return 0;
+ }
+ catch (std::system_error& SystemError)
+ {
+ if (IsOOM(SystemError.code()))
+ {
+ ZEN_WARN("out of memory when processing http request: '{}'", SystemError.what());
+ }
+ else if (IsOOD(SystemError.code()))
+ {
+ ZEN_WARN("out of disk space when processing http request: '{}'", SystemError.what());
+ }
+ else
+ {
+ ZEN_ERROR("failed processing http request: '{}'", SystemError.what());
+ }
+ ResetState();
+ return 1;
+ }
+ catch (std::bad_alloc& BadAlloc)
+ {
+ ZEN_WARN("out of memory when processing http request: '{}'", BadAlloc.what());
+ ResetState();
+ return 1;
+ }
+ catch (std::exception& Ex)
+ {
+ ZEN_ERROR("failed processing http request: '{}'", Ex.what());
+ ResetState();
+ return 1;
+ }
}
} // namespace zen