common_responses.h
1 /*
2 * Nebula Atom
3 
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #ifndef NAF_HTTP_COMMONRESPONSES
19 #define NAF_HTTP_COMMONRESPONSES
20 
21 
22 #include <string>
23 #include <map>
24 
25 #include <Poco/Net/HTTPServerResponse.h>
26 #include <Poco/JSON/JSON.h>
27 #include <Poco/JSON/Object.h>
28 
29 #include "nebulaatomConfig.h"
30 #include "files/file_manager.h"
31 #include "http/request.h"
32 
33 
34 namespace NAF
35 {
36  namespace HTTP
37  {
38  enum class ResponseType;
39  enum class Status;
40  class CommonResponses;
41  }
42 }
43 
44 using namespace Poco;
45 using namespace Poco::Net;
46 
47 
48 enum class NAF::HTTP::ResponseType
49 {
50  kError
51  ,kWarning
52  ,kInformation
53  ,kSuccess
54 };
55 
56 enum class NAF::HTTP::Status
57 {
58  kHTTP_OK = 200
59  ,kHTTP_BAD_REQUEST = 400
60  ,kHTTP_UNAUTHORIZED = 401
61  ,kHTTP_FORBIDDEN = 403
62  ,kHTTP_NOT_FOUND = 404
63  ,kHTTP_INTERNAL_SERVER_ERROR = 500
64  ,kHTTP_BAD_GATEWAY = 502
65  ,kHTTP_SERVICE_UNAVAILABLE = 503
66 };
67 
69 {
70  public:
71  struct Attributes
72  {
73  HTTPResponse::HTTPStatus http_status;
74  int status_int;
75  ResponseType response_type;
76  std::string message;
77  };
78 
80  ~CommonResponses();
81 
82  std::map<HTTP::Status, Attributes>& get_responses_()
83  {
84  auto& var = responses_;
85  return var;
86  }
87 
88  void CompoundResponse_(HTTP::Status status, JSON::Object::Ptr result_json);
89  void CompoundFillResponse_(HTTP::Status status, JSON::Object::Ptr result_json, std::string message);
90  void JSONResponse_(HTTP::Status status, std::string message);
91  void HTMLResponse_(HTTP::Status status, std::string message);
92  void CustomHTMLResponse_(HTTP::Status status, std::string html_message);
93  void FileResponse_(HTTP::Status status, std::string address);
94 
95  protected:
96  void FillResponses_();
97  void FillStatusMessage_(JSON::Object::Ptr json_object, HTTP::Status status, std::string message);
98 
99  private:
100  std::map<HTTP::Status, Attributes> responses_;
101 };
102 
103 #endif // NAF_HTTP_COMMONRESPONSES
Definition: common_responses.h:69
Definition: request.h:74
Definition: common_responses.h:72