NAWA  0.8
Web Application Framework for C++
Post.cpp
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2019-2021 Tobias Flaig.
8  *
9  * This file is part of nawa.
10  *
11  * nawa is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License,
13  * version 3, as published by the Free Software Foundation.
14  *
15  * nawa is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
26 
27 using namespace nawa;
28 using namespace std;
29 
30 struct request::Post::Data {
31  std::string contentType;
32  std::shared_ptr<std::string> rawPost;
33  std::unordered_multimap<std::string, File> fileMap;
34 
35  explicit Data(RequestInitContainer const& requestInit) : contentType(requestInit.postContentType),
36  rawPost(requestInit.rawPost),
37  fileMap(requestInit.postFiles) {}
38 };
39 
41 
42 request::Post::Post(RequestInitContainer const& requestInit) : GPC(requestInit, GPC::Source::POST) {
43  data = make_unique<Data>(requestInit);
44 }
45 
46 request::Post::operator bool() const {
47  return !(getMultimap().empty() && data->fileMap.empty());
48 }
49 
50 shared_ptr<string const> request::Post::getRaw() const {
51  return data->rawPost;
52 }
53 
55  return data->contentType;
56 }
57 
59  return !data->fileMap.empty();
60 }
61 
62 optional<File> request::Post::getFile(string const& key) const {
63  auto e = data->fileMap.find(key);
64  if (e != data->fileMap.end())
65  return e->second;
66  return nullopt;
67 }
68 
69 vector<File> request::Post::getFileVector(string const& key) const {
70  vector<File> ret;
71  auto e = data->fileMap.equal_range(key);
72  for (auto it = e.first; it != e.second; ++it) {
73  ret.push_back(it->second);
74  }
75  return ret;
76 }
77 
78 size_t request::Post::countFiles(string const& key) const {
79  return data->fileMap.count(key);
80 }
81 
82 std::unordered_multimap<std::string, File> const& request::Post::getFileMultimap() const {
83  return data->fileMap;
84 }
Post.h.
Container used by request handlers to initiate the nawa::Request object.
std::shared_ptr< std::string const > getRaw() const
Definition: Post.cpp:50
std::optional< File > getFile(std::string const &key) const
Definition: Post.cpp:62
std::string getContentType() const
Definition: Post.cpp:54
std::vector< File > getFileVector(std::string const &key) const
Definition: Post.cpp:69
std::unordered_multimap< std::string, File > const & getFileMultimap() const
Definition: Post.cpp:82
bool hasFiles() const
Definition: Post.cpp:58
size_t countFiles(std::string const &key) const
Definition: Post.cpp:78
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class)
Definition: macros.h:37
Definition: AppInit.h:31