Loading...
Searching...
No Matches
body.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_HTTP_BODY
20#define NAF_HTTP_BODY
21
22
23#include <istream>
24
25#include "Poco/StreamCopier.h"
26#include "Poco/NullStream.h"
27#include "Poco/URI.h"
28#include "Poco/Exception.h"
29#include <Poco/JSON/Object.h>
30#include <Poco/JSON/Array.h>
31#include <Poco/Net/NameValueCollection.h>
32#include <Poco/Net/MessageHeader.h>
33#include <Poco/Net/HTTPServerRequest.h>
34#include <Poco/Net/HTMLForm.h>
35
36#include "tools/manage_json.h"
37#include "files/file_manager.h"
38
39
40namespace NAF
41{
42 namespace HTTP
43 {
44 class Body;
45 }
46}
47
48using namespace Poco;
49
50
52{
53 public:
54 enum class Type
55 {
56 kFormMultipart
57 ,kFormURLEncoded
58 ,kJSON
59 ,kURI
60 };
61
62 using Ptr = std::shared_ptr<Body>;
63
64 Body();
65 ~Body(){}
66
67 Type get_body_type() const { return body_type_; }
68 URI::QueryParameters& get_query_parameters()
69 {
70 auto& var = query_parameters_;
71 return var;
72 }
73 Files::FileManager::Ptr& get_files_parameters()
74 {
75 auto& var = files_parameters_;
76 return var;
77 }
78 std::shared_ptr<HTMLForm>& get_form()
79 {
80 auto& var = form_;
81 return var;
82 }
83
84 void ReadFormMultipart_(Net::HTTPServerRequest& request);
85 void ReadFormURLEncoded_(Net::HTTPServerRequest& request, std::istream& stream);
86 void ReadJSON_(std::istream& stream);
87 void ReadFromURI_(std::string& uri);
88
89 private:
90 Type body_type_;
91 URI::QueryParameters query_parameters_;
92 Files::FileManager::Ptr files_parameters_;
93 std::shared_ptr<HTMLForm> form_;
94
95};
96
97#endif // NAF_HTTP_BODY
Definition body.h:52
Definition manage_json.h:48