NAWA  0.8
Web Application Framework for C++
Env.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 
24 #include <nawa/request/Env.h>
26 #include <nawa/util/utils.h>
27 #include <unordered_map>
28 
29 using namespace nawa;
30 using namespace std;
31 
32 struct request::Env::Data {
33  unordered_map<string, string> environment;
34 
35  explicit Data(RequestInitContainer const& initContainer) : environment(initContainer.environment) {}
36 };
37 
39 
40 request::Env::Env(RequestInitContainer const& initContainer) {
41  data = make_unique<Data>(initContainer);
42 }
43 
44 string request::Env::operator[](string const& envVar) const {
45  if (data->environment.count(envVar)) {
46  return data->environment.at(envVar);
47  }
48  return {};
49 }
50 
51 vector<string> request::Env::getRequestPath() const {
52  return utils::splitPath(operator[]("REQUEST_URI"));
53 }
Accessor class for environment variables.
Container used by request handlers to initiate the nawa::Request object.
std::vector< std::string > getRequestPath() const
Definition: Env.cpp:51
std::string operator[](std::string const &envVar) const
Definition: Env.cpp:44
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class)
Definition: macros.h:37
std::vector< std::string > splitPath(std::string const &pathString)
Definition: utils.cpp:476
Definition: AppInit.h:31
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.