Feature: Catch All Handler so the process does not die on failure
This commit is contained in:
parent
2bd34c2bb1
commit
516e33d165
1 changed files with 39 additions and 21 deletions
|
@ -1,6 +1,10 @@
|
||||||
#include "Includes/VWeb.h"
|
#include "Includes/VWeb.h"
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <exception>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
namespace VWeb {
|
namespace VWeb {
|
||||||
|
|
||||||
HttpMethod StringToHTTPMethod(std::string &method) {
|
HttpMethod StringToHTTPMethod(std::string &method) {
|
||||||
|
@ -82,6 +86,12 @@ void ParseParameters(Request &request, RequestHandler &requestHandler) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::string faultyRequest = R"_(
|
||||||
|
HTTP/1.1 500 Bad Gateway\r
|
||||||
|
Content-Type: text/html\r
|
||||||
|
Content-Length: 0\r
|
||||||
|
ETag: "66369d26-1f1"\r\n
|
||||||
|
)_";
|
||||||
|
|
||||||
struct RequestJob : public WorkerJob {
|
struct RequestJob : public WorkerJob {
|
||||||
Ref<Request> MRequest{};
|
Ref<Request> MRequest{};
|
||||||
|
@ -90,6 +100,7 @@ struct RequestJob : public WorkerJob {
|
||||||
RequestHandler *MRequestHandler{nullptr};
|
RequestHandler *MRequestHandler{nullptr};
|
||||||
|
|
||||||
void Execute() override {
|
void Execute() override {
|
||||||
|
try {
|
||||||
if (!ParseRequest(MRequest)) {
|
if (!ParseRequest(MRequest)) {
|
||||||
fprintf(stderr, "[Request] >> Request failed to parse\n");
|
fprintf(stderr, "[Request] >> Request failed to parse\n");
|
||||||
SocketUtils::Close(MRequest->ID);
|
SocketUtils::Close(MRequest->ID);
|
||||||
|
@ -112,6 +123,13 @@ struct RequestJob : public WorkerJob {
|
||||||
MRequestHandler->AddSendResponse(
|
MRequestHandler->AddSendResponse(
|
||||||
{0, (ssize_t)content.size(), MRequest->ID, content});
|
{0, (ssize_t)content.size(), MRequest->ID, content});
|
||||||
MMiddleWareHandler->Shutdown(MRequest, response);
|
MMiddleWareHandler->Shutdown(MRequest, response);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"[VWEB] >> Failed to handle Requests... Error thrown\n%s\n",
|
||||||
|
e.what());
|
||||||
|
MRequestHandler->AddSendResponse(
|
||||||
|
{0, (ssize_t)faultyRequest.size(), MRequest->ID, faultyRequest});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RequestHandler::RequestHandler(const Ref<SocketManager> &manager)
|
RequestHandler::RequestHandler(const Ref<SocketManager> &manager)
|
||||||
|
|
Loading…
Reference in a new issue