diff options
author | ipknHama <ipknhama@gmail.com> | 2014-04-20 17:45:10 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2014-04-20 17:45:59 +0900 |
commit | 1173eba33240071a52991f6755623a324742d0b7 (patch) | |
tree | dca3c85e2a2a47c935a52ff70508336b50bb42fe /common.h | |
parent | 5cdffdf9f75997bfa821203123305b9f8c24b463 (diff) | |
download | crow-1173eba33240071a52991f6755623a324742d0b7.tar.gz crow-1173eba33240071a52991f6755623a324742d0b7.zip |
add support for handlers with request argument, add http method
Diffstat (limited to 'common.h')
-rw-r--r-- | common.h | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -1,9 +1,47 @@ #pragma once #include <string> +#include <stdexcept> +#include "utility.h" namespace flask { + enum class HTTPMethod + { + DELETE, + GET, + HEAD, + POST, + PUT, + CONNECT, + OPTIONS, + TRACE, + }; + + std::string method_name(HTTPMethod method) + { + switch(method) + { + case HTTPMethod::DELETE: + return "DELETE"; + case HTTPMethod::GET: + return "GET"; + case HTTPMethod::HEAD: + return "HEAD"; + case HTTPMethod::POST: + return "POST"; + case HTTPMethod::PUT: + return "PUT"; + case HTTPMethod::CONNECT: + return "CONNECT"; + case HTTPMethod::OPTIONS: + return "OPTIONS"; + case HTTPMethod::TRACE: + return "TRACE"; + } + return "invalid"; + } + enum class ParamType { INT, @@ -68,3 +106,18 @@ namespace flask return string_params[index]; } } + +constexpr flask::HTTPMethod operator "" _method(const char* str, size_t len) +{ + return + flask::black_magic::is_equ_p(str, "GET", 3) ? flask::HTTPMethod::GET : + flask::black_magic::is_equ_p(str, "DELETE", 6) ? flask::HTTPMethod::DELETE : + flask::black_magic::is_equ_p(str, "HEAD", 4) ? flask::HTTPMethod::HEAD : + flask::black_magic::is_equ_p(str, "POST", 4) ? flask::HTTPMethod::POST : + flask::black_magic::is_equ_p(str, "PUT", 3) ? flask::HTTPMethod::PUT : + flask::black_magic::is_equ_p(str, "OPTIONS", 7) ? flask::HTTPMethod::OPTIONS : + flask::black_magic::is_equ_p(str, "CONNECT", 7) ? flask::HTTPMethod::CONNECT : + flask::black_magic::is_equ_p(str, "TRACE", 5) ? flask::HTTPMethod::TRACE : + throw std::runtime_error("invalid http method"); +}; + |