@@ -115,24 +115,9 @@ namespace lklibs {
115
115
*
116
116
* @param method: HTTP method to be used for the request
117
117
*/
118
- HttpRequest &setMethod (const HttpMethod &method) {
119
-
120
- this ->method = [method] {
121
- switch (method) {
122
- case HttpMethod::GET:
123
- return " GET" ;
124
- case HttpMethod::POST:
125
- return " POST" ;
126
- case HttpMethod::PUT:
127
- return " PUT" ;
128
- case HttpMethod::DELETE_:
129
- return " DELETE" ;
130
- case HttpMethod::PATCH:
131
- return " PATCH" ;
132
- default :
133
- return " GET" ;
134
- }
135
- }();
118
+ HttpRequest &setMethod (const HttpMethod &method) noexcept {
119
+
120
+ this ->method = HttpMethodStrings[static_cast <int >(method)];
136
121
137
122
return *this ;
138
123
}
@@ -142,7 +127,7 @@ namespace lklibs {
142
127
*
143
128
* @param queryString: Query string to be sent with the request
144
129
*/
145
- HttpRequest &setQueryString (const std::string &queryString) {
130
+ HttpRequest &setQueryString (const std::string &queryString) noexcept {
146
131
147
132
if (this ->url .find (' ?' ) != std::string::npos) {
148
133
@@ -163,7 +148,7 @@ namespace lklibs {
163
148
*
164
149
* @param payload: Payload to be sent with the request
165
150
*/
166
- HttpRequest &setPayload (const std::string &payload) {
151
+ HttpRequest &setPayload (const std::string &payload) noexcept {
167
152
168
153
this ->payload = payload;
169
154
@@ -173,7 +158,7 @@ namespace lklibs {
173
158
/* *
174
159
* @brief Set the return format for the request as binary
175
160
*/
176
- HttpRequest &returnAsBinary () {
161
+ HttpRequest &returnAsBinary () noexcept {
177
162
178
163
this ->returnFormat = ReturnFormat::BINARY;
179
164
@@ -183,7 +168,7 @@ namespace lklibs {
183
168
/* *
184
169
* @brief Ignore SSL errors when making HTTP requests
185
170
*/
186
- HttpRequest &ignoreSslErrors () {
171
+ HttpRequest &ignoreSslErrors () noexcept {
187
172
188
173
this ->sslErrorsWillBeIgnored = true ;
189
174
@@ -196,7 +181,7 @@ namespace lklibs {
196
181
* @param key: Header key
197
182
* @param value: Header value
198
183
*/
199
- HttpRequest &addHeader (const std::string &key, const std::string &value) {
184
+ HttpRequest &addHeader (const std::string &key, const std::string &value) noexcept {
200
185
201
186
this ->headers [key] = value;
202
187
@@ -223,6 +208,14 @@ namespace lklibs {
223
208
BINARY
224
209
};
225
210
211
+ const char * HttpMethodStrings[5 ] = {
212
+ " GET" ,
213
+ " POST" ,
214
+ " PUT" ,
215
+ " DELETE" ,
216
+ " PATCH"
217
+ };
218
+
226
219
std::string url;
227
220
std::string method = " GET" ;
228
221
std::string payload;
0 commit comments