NAWA 0.9
Web Application Framework for C++
Env.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 Tobias Flaig.
3 *
4 * This file is part of nawa.
5 *
6 * nawa is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License,
8 * version 3, as published by the Free Software Foundation.
9 *
10 * nawa 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 Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24#include <nawa/request/Env.h>
26#include <nawa/util/utils.h>
27#include <unordered_map>
28
29using namespace nawa;
30using namespace std;
31
32struct request::Env::Data {
33 unordered_map<string, string> environment;
34
35 explicit Data(RequestInitContainer const& initContainer) : environment(initContainer.environment) {}
36};
37
39
40request::Env::Env(RequestInitContainer const& initContainer) {
41 data = make_unique<Data>(initContainer);
42}
43
44std::string request::Env::operator[](std::string const& envVar) const {
45 if (data->environment.count(envVar)) {
46 return data->environment.at(envVar);
47 }
48 return {};
49}
50
51std::vector<std::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
#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.