7 #include "crow/utility.h"
13 const std::string crlf(
"\r\n");
15 enum class HTTPMethod : char
110 constexpr
const char* method_strings[] =
156 inline std::string method_name(HTTPMethod method)
158 if (CROW_LIKELY(method < HTTPMethod::InternalMethodCount))
160 return method_strings[(
unsigned char)method];
170 SWITCHING_PROTOCOLS = 101,
175 NON_AUTHORITATIVE_INFORMATION = 203,
178 PARTIAL_CONTENT = 206,
180 MULTIPLE_CHOICES = 300,
181 MOVED_PERMANENTLY = 301,
185 TEMPORARY_REDIRECT = 307,
186 PERMANENT_REDIRECT = 308,
192 METHOD_NOT_ALLOWED = 405,
193 NOT_ACCEPTABLE = 406,
194 PROXY_AUTHENTICATION_REQUIRED = 407,
197 PAYLOAD_TOO_LARGE = 413,
198 UNSUPPORTED_MEDIA_TYPE = 415,
199 RANGE_NOT_SATISFIABLE = 416,
200 EXPECTATION_FAILED = 417,
201 PRECONDITION_REQUIRED = 428,
202 TOO_MANY_REQUESTS = 429,
203 UNAVAILABLE_FOR_LEGAL_REASONS = 451,
205 INTERNAL_SERVER_ERROR = 500,
206 NOT_IMPLEMENTED = 501,
208 SERVICE_UNAVAILABLE = 503,
209 GATEWAY_TIMEOUT = 504,
210 VARIANT_ALSO_NEGOTIATES = 506
215 enum class ParamType : char
227 struct routing_params
229 std::vector<int64_t> int_params;
230 std::vector<uint64_t> uint_params;
231 std::vector<double> double_params;
232 std::vector<std::string> string_params;
234 void debug_print()
const
236 std::cerr <<
"routing_params" << std::endl;
237 for (
auto i : int_params)
238 std::cerr << i <<
", ";
239 std::cerr << std::endl;
240 for (
auto i : uint_params)
241 std::cerr << i <<
", ";
242 std::cerr << std::endl;
243 for (
auto i : double_params)
244 std::cerr << i <<
", ";
245 std::cerr << std::endl;
246 for (
auto& i : string_params)
247 std::cerr << i <<
", ";
248 std::cerr << std::endl;
252 T get(
unsigned)
const;
256 inline int64_t routing_params::get<int64_t>(
unsigned index)
const
258 return int_params[index];
262 inline uint64_t routing_params::get<uint64_t>(
unsigned index)
const
264 return uint_params[index];
268 inline double routing_params::get<double>(
unsigned index)
const
270 return double_params[index];
274 inline std::string routing_params::get<std::string>(
unsigned index)
const
276 return string_params[index];
283 std::vector<uint16_t> blueprint_indices;
284 routing_params r_params;
289 routing_handle_result(uint16_t rule_index_, std::vector<uint16_t> blueprint_indices_, routing_params r_params_):
290 rule_index(rule_index_),
291 blueprint_indices(blueprint_indices_),
292 r_params(r_params_) {}
294 routing_handle_result(uint16_t rule_index_, std::vector<uint16_t> blueprint_indices_, routing_params r_params_, HTTPMethod method_):
295 rule_index(rule_index_),
296 blueprint_indices(blueprint_indices_),
303 #ifndef CROW_MSVC_WORKAROUND
304 constexpr crow::HTTPMethod method_from_string(
const char* str)
306 return crow::black_magic::is_equ_p(str,
"GET", 3) ? crow::HTTPMethod::Get :
307 crow::black_magic::is_equ_p(str,
"DELETE", 6) ? crow::HTTPMethod::Delete :
308 crow::black_magic::is_equ_p(str,
"HEAD", 4) ? crow::HTTPMethod::Head :
309 crow::black_magic::is_equ_p(str,
"POST", 4) ? crow::HTTPMethod::Post :
310 crow::black_magic::is_equ_p(str,
"PUT", 3) ? crow::HTTPMethod::Put :
312 crow::black_magic::is_equ_p(str,
"OPTIONS", 7) ? crow::HTTPMethod::Options :
313 crow::black_magic::is_equ_p(str,
"CONNECT", 7) ? crow::HTTPMethod::Connect :
314 crow::black_magic::is_equ_p(str,
"TRACE", 5) ? crow::HTTPMethod::Trace :
316 crow::black_magic::is_equ_p(str,
"PATCH", 5) ? crow::HTTPMethod::Patch :
317 crow::black_magic::is_equ_p(str,
"PURGE", 5) ? crow::HTTPMethod::Purge :
318 crow::black_magic::is_equ_p(str,
"COPY", 4) ? crow::HTTPMethod::Copy :
319 crow::black_magic::is_equ_p(str,
"LOCK", 4) ? crow::HTTPMethod::Lock :
320 crow::black_magic::is_equ_p(str,
"MKCOL", 5) ? crow::HTTPMethod::MkCol :
321 crow::black_magic::is_equ_p(str,
"MOVE", 4) ? crow::HTTPMethod::Move :
322 crow::black_magic::is_equ_p(str,
"PROPFIND", 8) ? crow::HTTPMethod::Propfind :
323 crow::black_magic::is_equ_p(str,
"PROPPATCH", 9) ? crow::HTTPMethod::Proppatch :
324 crow::black_magic::is_equ_p(str,
"SEARCH", 6) ? crow::HTTPMethod::Search :
325 crow::black_magic::is_equ_p(str,
"UNLOCK", 6) ? crow::HTTPMethod::Unlock :
326 crow::black_magic::is_equ_p(str,
"BIND", 4) ? crow::HTTPMethod::Bind :
327 crow::black_magic::is_equ_p(str,
"REBIND", 6) ? crow::HTTPMethod::Rebind :
328 crow::black_magic::is_equ_p(str,
"UNBIND", 6) ? crow::HTTPMethod::Unbind :
329 crow::black_magic::is_equ_p(str,
"ACL", 3) ? crow::HTTPMethod::Acl :
331 crow::black_magic::is_equ_p(str,
"REPORT", 6) ? crow::HTTPMethod::Report :
332 crow::black_magic::is_equ_p(str,
"MKACTIVITY", 10) ? crow::HTTPMethod::MkActivity :
333 crow::black_magic::is_equ_p(str,
"CHECKOUT", 8) ? crow::HTTPMethod::Checkout :
334 crow::black_magic::is_equ_p(str,
"MERGE", 5) ? crow::HTTPMethod::Merge :
336 crow::black_magic::is_equ_p(str,
"MSEARCH", 7) ? crow::HTTPMethod::MSearch :
337 crow::black_magic::is_equ_p(str,
"NOTIFY", 6) ? crow::HTTPMethod::Notify :
338 crow::black_magic::is_equ_p(str,
"SUBSCRIBE", 9) ? crow::HTTPMethod::Subscribe :
339 crow::black_magic::is_equ_p(str,
"UNSUBSCRIBE", 11) ? crow::HTTPMethod::Unsubscribe :
341 crow::black_magic::is_equ_p(str,
"MKCALENDAR", 10) ? crow::HTTPMethod::MkCalendar :
343 crow::black_magic::is_equ_p(str,
"LINK", 4) ? crow::HTTPMethod::Link :
344 crow::black_magic::is_equ_p(str,
"UNLINK", 6) ? crow::HTTPMethod::Unlink :
346 crow::black_magic::is_equ_p(str,
"SOURCE", 6) ? crow::HTTPMethod::Source :
347 throw std::runtime_error(
"invalid http method");
350 constexpr crow::HTTPMethod
operator"" _method(
const char* str,
size_t )
352 return method_from_string( str );
The main namespace of the library. In this namespace is defined the most important classes and functi...