NAWA 0.9
Web Application Framework for C++
Connection.h
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#ifndef NAWA_RESPONSE_H
25#define NAWA_RESPONSE_H
26
27#include <nawa/config/Config.h>
33#include <ostream>
34#include <string>
35#include <unordered_map>
36
37namespace nawa {
41 class Connection {
43
44 public:
46
51 [[nodiscard]] nawa::Request const& request() const noexcept;
52
57 nawa::Session& session() noexcept;
58
63 [[nodiscard]] nawa::Session const& session() const noexcept;
64
71 nawa::Config& config() noexcept;
72
78 [[nodiscard]] nawa::Config const& config() const noexcept;
79
84 std::ostream& responseStream() noexcept;
85
90 explicit Connection(ConnectionInitContainer const& connectionInit);
91
97 void setResponseBody(std::string content);
98
104 void setStatus(unsigned int status);
105
114 void setHeader(std::string key, std::string value);
115
122 void addHeader(std::string key, std::string value);
123
130 void unsetHeader(std::string key);
131
141 void setCookie(std::string const& key, Cookie cookie);
142
151 void setCookie(std::string const& key, std::string cookieContent);
152
158 void unsetCookie(const std::string& key);
159
165 void setCookiePolicy(Cookie policy);
166
183 void sendFile(std::string const& path, std::string const& contentType = "", bool forceDownload = false,
184 std::string const& downloadFilename = "", bool checkIfModifiedSince = false);
185
190 std::string getResponseBody();
191
196 [[nodiscard]] unsigned int getStatus() const;
197
203 [[nodiscard]] std::unordered_multimap<std::string, std::string> getHeaders(bool includeCookies = true) const;
204
211 void flushResponse();
212
222 bool applyFilters(AccessFilterList const& accessFilters);
223 };
224}// namespace nawa
225
226#endif//NAWA_RESPONSE_H
Reader for config files and accessor to config values.
Structure for creating Cookie objects. Content can be set by using a constructor.
Class which represents request objects.
Class for managing sessions and getting and setting connection-independent session data.
nawa::Session & session() noexcept
Definition: Connection.cpp:361
void addHeader(std::string key, std::string value)
Definition: Connection.cpp:224
void setCookiePolicy(Cookie policy)
Definition: Connection.cpp:349
void unsetHeader(std::string key)
Definition: Connection.cpp:230
nawa::Config & config() noexcept
Definition: Connection.cpp:369
void setStatus(unsigned int status)
Definition: Connection.cpp:345
unsigned int getStatus() const
Definition: Connection.cpp:353
void setCookie(std::string const &key, Cookie cookie)
Definition: Connection.cpp:314
void setHeader(std::string key, std::string value)
Definition: Connection.cpp:218
std::ostream & responseStream() noexcept
Definition: Connection.cpp:377
std::unordered_multimap< std::string, std::string > getHeaders(bool includeCookies=true) const
Definition: Connection.cpp:236
bool applyFilters(AccessFilterList const &accessFilters)
Definition: Connection.cpp:381
std::string getResponseBody()
Definition: Connection.cpp:297
nawa::Request const & request() const noexcept
Definition: Connection.cpp:357
void sendFile(std::string const &path, std::string const &contentType="", bool forceDownload=false, std::string const &downloadFilename="", bool checkIfModifiedSince=false)
Definition: Connection.cpp:139
void unsetCookie(const std::string &key)
Definition: Connection.cpp:328
void setResponseBody(std::string content)
Definition: Connection.cpp:134
Forward declarations.
Macros for frequently used patterns.
#define NAWA_DEFAULT_DESTRUCTOR_DEF(Class)
Definition: macros.h:34
#define NAWA_PRIVATE_DATA()
Definition: macros.h:30
Definition: AppInit.h:31