7#include "crow/utility.h"
13 const std::string crlf(
"\r\n");
14 const std::string crlfcrlf(
"\r\n\r\n");
16 enum class HTTPMethod :
char
111 constexpr const char* method_strings[] =
157 inline std::string method_name(HTTPMethod method)
159 if (CROW_LIKELY(method < HTTPMethod::InternalMethodCount))
161 return method_strings[
static_cast<unsigned int>(method)];
171 SWITCHING_PROTOCOLS = 101,
176 NON_AUTHORITATIVE_INFORMATION = 203,
179 PARTIAL_CONTENT = 206,
180 WEBDAV_MULTI_STATUS = 207,
181 MULTIPLE_CHOICES = 300,
182 MOVED_PERMANENTLY = 301,
186 TEMPORARY_REDIRECT = 307,
187 PERMANENT_REDIRECT = 308,
193 METHOD_NOT_ALLOWED = 405,
194 NOT_ACCEPTABLE = 406,
195 PROXY_AUTHENTICATION_REQUIRED = 407,
198 PAYLOAD_TOO_LARGE = 413,
199 UNSUPPORTED_MEDIA_TYPE = 415,
200 RANGE_NOT_SATISFIABLE = 416,
201 EXPECTATION_FAILED = 417,
203 WEBDAV_PRECONDITION_FAILED = 412,
204 WEBDAV_REQUEST_URI_TOO_LONG = 414,
205 WEBDAV_UNPROCESSABLE_ENTITY = 422,
207 WEBDAV_FAILED_DEPENDENCY = 424,
209 PRECONDITION_REQUIRED = 428,
210 TOO_MANY_REQUESTS = 429,
211 UNAVAILABLE_FOR_LEGAL_REASONS = 451,
213 INTERNAL_SERVER_ERROR = 500,
214 NOT_IMPLEMENTED = 501,
216 SERVICE_UNAVAILABLE = 503,
217 GATEWAY_TIMEOUT = 504,
218 VARIANT_ALSO_NEGOTIATES = 506,
219 WEBDAV_INSUFFICIENT_STORAGE = 507
224 enum class ParamType :
char
236 struct routing_params
238 std::vector<int64_t> int_params;
239 std::vector<uint64_t> uint_params;
240 std::vector<double> double_params;
241 std::vector<std::string> string_params;
243 void debug_print()
const
245 std::cerr <<
"routing_params" << std::endl;
246 for (
auto i : int_params)
247 std::cerr << i <<
", ";
248 std::cerr << std::endl;
249 for (
auto i : uint_params)
250 std::cerr << i <<
", ";
251 std::cerr << std::endl;
252 for (
auto i : double_params)
253 std::cerr << i <<
", ";
254 std::cerr << std::endl;
255 for (
auto& i : string_params)
256 std::cerr << i <<
", ";
257 std::cerr << std::endl;
261 T get(
unsigned)
const;
265 inline int64_t routing_params::get<int64_t>(
unsigned index)
const
267 return int_params[index];
271 inline uint64_t routing_params::get<uint64_t>(
unsigned index)
const
273 return uint_params[index];
277 inline double routing_params::get<double>(
unsigned index)
const
279 return double_params[index];
283 inline std::string routing_params::get<std::string>(
unsigned index)
const
285 return string_params[index];
291 bool catch_all{
false};
293 std::vector<size_t> blueprint_indices;
294 routing_params r_params;
299 routing_handle_result(
size_t rule_index_, std::vector<size_t> blueprint_indices_, routing_params r_params_):
300 rule_index(rule_index_),
301 blueprint_indices(blueprint_indices_),
302 r_params(r_params_) {}
304 routing_handle_result(
size_t rule_index_, std::vector<size_t> blueprint_indices_, routing_params r_params_, HTTPMethod method_):
305 rule_index(rule_index_),
306 blueprint_indices(blueprint_indices_),
313#ifndef CROW_MSVC_WORKAROUND
314constexpr crow::HTTPMethod method_from_string(
const char* str)
316 return crow::black_magic::is_equ_p(str,
"GET", 3) ? crow::HTTPMethod::Get :
317 crow::black_magic::is_equ_p(str,
"DELETE", 6) ? crow::HTTPMethod::Delete :
318 crow::black_magic::is_equ_p(str,
"HEAD", 4) ? crow::HTTPMethod::Head :
319 crow::black_magic::is_equ_p(str,
"POST", 4) ? crow::HTTPMethod::Post :
320 crow::black_magic::is_equ_p(str,
"PUT", 3) ? crow::HTTPMethod::Put :
322 crow::black_magic::is_equ_p(str,
"OPTIONS", 7) ? crow::HTTPMethod::Options :
323 crow::black_magic::is_equ_p(str,
"CONNECT", 7) ? crow::HTTPMethod::Connect :
324 crow::black_magic::is_equ_p(str,
"TRACE", 5) ? crow::HTTPMethod::Trace :
326 crow::black_magic::is_equ_p(str,
"PATCH", 5) ? crow::HTTPMethod::Patch :
327 crow::black_magic::is_equ_p(str,
"PURGE", 5) ? crow::HTTPMethod::Purge :
328 crow::black_magic::is_equ_p(str,
"COPY", 4) ? crow::HTTPMethod::Copy :
329 crow::black_magic::is_equ_p(str,
"LOCK", 4) ? crow::HTTPMethod::Lock :
330 crow::black_magic::is_equ_p(str,
"MKCOL", 5) ? crow::HTTPMethod::MkCol :
331 crow::black_magic::is_equ_p(str,
"MOVE", 4) ? crow::HTTPMethod::Move :
332 crow::black_magic::is_equ_p(str,
"PROPFIND", 8) ? crow::HTTPMethod::Propfind :
333 crow::black_magic::is_equ_p(str,
"PROPPATCH", 9) ? crow::HTTPMethod::Proppatch :
334 crow::black_magic::is_equ_p(str,
"SEARCH", 6) ? crow::HTTPMethod::Search :
335 crow::black_magic::is_equ_p(str,
"UNLOCK", 6) ? crow::HTTPMethod::Unlock :
336 crow::black_magic::is_equ_p(str,
"BIND", 4) ? crow::HTTPMethod::Bind :
337 crow::black_magic::is_equ_p(str,
"REBIND", 6) ? crow::HTTPMethod::Rebind :
338 crow::black_magic::is_equ_p(str,
"UNBIND", 6) ? crow::HTTPMethod::Unbind :
339 crow::black_magic::is_equ_p(str,
"ACL", 3) ? crow::HTTPMethod::Acl :
341 crow::black_magic::is_equ_p(str,
"REPORT", 6) ? crow::HTTPMethod::Report :
342 crow::black_magic::is_equ_p(str,
"MKACTIVITY", 10) ? crow::HTTPMethod::MkActivity :
343 crow::black_magic::is_equ_p(str,
"CHECKOUT", 8) ? crow::HTTPMethod::Checkout :
344 crow::black_magic::is_equ_p(str,
"MERGE", 5) ? crow::HTTPMethod::Merge :
346 crow::black_magic::is_equ_p(str,
"MSEARCH", 7) ? crow::HTTPMethod::MSearch :
347 crow::black_magic::is_equ_p(str,
"NOTIFY", 6) ? crow::HTTPMethod::Notify :
348 crow::black_magic::is_equ_p(str,
"SUBSCRIBE", 9) ? crow::HTTPMethod::Subscribe :
349 crow::black_magic::is_equ_p(str,
"UNSUBSCRIBE", 11) ? crow::HTTPMethod::Unsubscribe :
351 crow::black_magic::is_equ_p(str,
"MKCALENDAR", 10) ? crow::HTTPMethod::MkCalendar :
353 crow::black_magic::is_equ_p(str,
"LINK", 4) ? crow::HTTPMethod::Link :
354 crow::black_magic::is_equ_p(str,
"UNLINK", 6) ? crow::HTTPMethod::Unlink :
356 crow::black_magic::is_equ_p(str,
"SOURCE", 6) ? crow::HTTPMethod::Source :
357 throw std::runtime_error(
"invalid http method");
360constexpr crow::HTTPMethod
operator""_method(
const char* str,
size_t )
362 return method_from_string( str );
The main namespace of the library. In this namespace is defined the most important classes and functi...