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_DELETE = "DELETE";
38  const std::string HTTP_OPTIONS = "OPTIONS";
39  const std::string HTTP_HEAD = "HEAD";
40  const std::string HTTP_PATCH = "PATCH";
41  enum class EnumMethods;
42  class Methods;
43  }
44 }
45 
46 
47 enum class NAF::HTTP::EnumMethods
48 {
49  kHTTP_GET
50  ,kHTTP_POST
51  ,kHTTP_PUT
52  ,kHTTP_DEL
53  ,kHTTP_OPTIONS
54  ,kHTTP_HEAD
55  ,kHTTP_PATCH
56  ,kNULL
57 };
58 
60 {
61  public:
62  using MethodProcess = std::function<void(HTTP::Methods&)>;
63 
64  struct MethodStruct
65  {
66  HTTP::EnumMethods method;
67  MethodProcess process;
68  };
69 
70  Methods();
71  virtual ~Methods(){}
72 
73  std::map<const std::string, EnumMethods>& get_map_string_methods()
74  {
75  auto& var = map_string_methods_;
76  return var;
77  }
78  std::map<EnumMethods, const std::string>& get_map_enum_methods()
79  {
80  auto& var = map_enum_methods_;
81  return var;
82  }
83 
84  EnumMethods GetMethod_(const std::string method);
85  const std::string GetMethod_(EnumMethods& method);
86  void AddProcess_(const std::string method, MethodProcess process);
87  bool EvaluateProcess_(std::string request_method);
88  std::string IdentifyMethod_(std::string method);
89 
90  protected:
91  void MapMethods_();
92 
93  private:
94  std::map<const std::string, EnumMethods> map_string_methods_;
95  std::map<EnumMethods, const std::string> map_enum_methods_;
96  std::list<MethodStruct> process_;
97 };
98 
99 #endif // NAF_HTTPMETHODS
Definition: methods.h:60
Definition: methods.h:65