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>
25#include <nawa/request/RequestInitContainer.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 vector<string> acceptLanguages;
35
36 explicit Data(RequestInitContainer const& initContainer) : environment(initContainer.environment),
37 acceptLanguages(initContainer.acceptLanguages) {}
38};
39
41
42request::Env::Env(RequestInitContainer const& initContainer) {
43 data = make_unique<Data>(initContainer);
44}
45
46string request::Env::operator[](string const& envVar) const {
47 if (data->environment.count(envVar)) {
48 return data->environment.at(envVar);
49 }
50 return {};
51}
52
53vector<string> request::Env::getAcceptLanguages() const {
54 return data->acceptLanguages;
55}
56
57vector<string> request::Env::getRequestPath() const {
58 return utils::splitPath(operator[]("REQUEST_URI"));
59}
Accessor class for environment variables.
std::vector< std::string > getRequestPath() const
Definition: Env.cpp:57
std::vector< std::string > getAcceptLanguages() const
Definition: Env.cpp:53
#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:446
Definition: AppInit.h:31
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.