methods.h
1 /*
2 * <one line to give the program's name and a brief idea of what it does.>
3 * Copyright (C) 2021 <copyright holder> <email>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef NAF_HTTPMETHODS
20 #define NAF_HTTPMETHODS
21 
22 #include <map>
23 #include <string>
24 #include <functional>
25 #include <list>
26 #include <exception>
27 
28 
29 namespace NAF
30 {
31  namespace HTTP
32  {
33  const std::string HTTP_GET = "GET";
34  const std::string HTTP_POST = "POST";
35  const std::string HTTP_PUT = "PUT";
36  const std::string HTTP_DEL = "DEL";
37  const std::string HTTP_OPTIONS = "OPTIONS";
38  const std::string HTTP_HEAD = "HEAD";
39  const std::string HTTP_PATCH = "PATCH";
40  enum class EnumMethods;
41  class Methods;
42  }
43 }
44 
45 
46 enum class NAF::HTTP::EnumMethods
47 {
48  kHTTP_GET
49  ,kHTTP_POST
50  ,kHTTP_PUT
51  ,kHTTP_DEL
52  ,kHTTP_OPTIONS
53  ,kHTTP_HEAD
54  ,kHTTP_PATCH
55  ,kNULL
56 };
57 
59 {
60  public:
61  using MethodProcess = std::function<void(HTTP::Methods&)>;
62 
63  struct MethodStruct
64  {
65  HTTP::EnumMethods method;
66  MethodProcess process;
67  };
68 
69  Methods();
70  virtual ~Methods(){}
71 
72  std::map<const std::string, EnumMethods>& get_map_string_methods()
73  {
74  auto& var = map_string_methods_;
75  return var;
76  }
77  std::map<EnumMethods, const std::string>& get_map_enum_methods()
78  {
79  auto& var = map_enum_methods_;
80  return var;
81  }
82 
83  EnumMethods GetMethod_(const std::string method);
84  const std::string GetMethod_(EnumMethods& method);
85  void AddProcess_(const std::string method, MethodProcess process);
86  bool EvaluateProcess_(std::string request_method);
87  std::string IdentifyMethod_(std::string method);
88 
89  protected:
90  void MapMethods_();
91 
92  private:
93  std::map<const std::string, EnumMethods> map_string_methods_;
94  std::map<EnumMethods, const std::string> map_enum_methods_;
95  std::list<MethodStruct> process_;
96 };
97 
98 #endif // NAF_HTTPMETHODS
Definition: methods.h:59
Definition: methods.h:64