WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
BaseExecutor.cpp
1#include "BaseExecutor.h"
2
3using namespace std;
4
5static void isImplemented
6(
7 vector<string>& result,
9 const string& methodName,
12);
13
14namespace framework
15{
20
22 {
23 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
24 }
25
27 {
28 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
29 }
30
32 {
33 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
34 }
35
37 {
38 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
39 }
40
42 {
43 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
44 }
45
47 {
48 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
49 }
50
52 {
53#ifdef NDEBUG
54 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
55#endif
56
57 vector<string> methods = { "OPTIONS" };
58 string allowHeader;
59
60 isImplemented(methods, request, "GET", &BaseExecutor::doGet, *this);
61 isImplemented(methods, request, "POST", &BaseExecutor::doPost, *this);
62 isImplemented(methods, request, "HEAD", &BaseExecutor::doHead, *this);
63 isImplemented(methods, request, "PUT", &BaseExecutor::doPut, *this);
64 isImplemented(methods, request, "DELETE", &BaseExecutor::doDelete, *this);
65 isImplemented(methods, request, "PATCH", &BaseExecutor::doPatch, *this);
66 isImplemented(methods, request, "TRACE", &BaseExecutor::doTrace, *this);
67 isImplemented(methods, request, "CONNECT", &BaseExecutor::doConnect, *this);
68
69 for (size_t i = 0; i < methods.size(); i++)
70 {
71 allowHeader += methods[i];
72
73 if (i + 1 != methods.size())
74 {
75 allowHeader += ", ";
76 }
77 }
78
79 response.addHeader("Allow", allowHeader);
80 }
81
83 {
84#ifdef NDEBUG
85 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
86#endif
87
88 response.addBody(request.getParser().getRawData());
89 }
90
92 {
93 throw exceptions::NotImplementedException(typeid(*this).name(), __func__);
94 }
95}
96
97inline void isImplemented
98(
99 vector<string>& result,
100 framework::HTTPRequest& request,
101 const string& methodName,
104)
105{
107
108 try
109 {
110 (executor.*method)(request, response);
111
112 result.push_back(methodName);
113 }
115 { //-V565
116
117 }
118 catch (...)
119 {
120 result.push_back(methodName);
121 }
122}
Base class for all executors.
virtual void doPatch(HTTPRequest &request, HTTPResponse &response)
Process PATCH request.
virtual void doPut(HTTPRequest &request, HTTPResponse &response)
Process PUT request.
virtual void doGet(HTTPRequest &request, HTTPResponse &response)
Process GET request.
virtual void doPost(HTTPRequest &request, HTTPResponse &response)
Process POST request.
virtual void doDelete(HTTPRequest &request, HTTPResponse &response)
Process DELETE request.
virtual void doTrace(HTTPRequest &request, HTTPResponse &response)
Process TRACE request.
virtual void doOptions(HTTPRequest &request, HTTPResponse &response)
Process OPTIONS request.
virtual void doHead(HTTPRequest &request, HTTPResponse &response)
Process HEAD request.
virtual void doConnect(HTTPRequest &request, HTTPResponse &response)
Process CONNECT request.
virtual void init(const utility::JSONSettingsParser::ExecutorSettings &settings)
Initializing executor before use.
Parsing HTTP request.
Definition HTTPRequest.h:25
const web::HTTPParser & getParser() const
HTTP parser getter.
HTTPBuilder wrapper.
void addBody(const std::string &body)
void addHeader(const std::string &name, const std::string &value)
Set additional HTTP header.
Default exception for all HTTP methods in BaseExecutor.