40 forwardFilter.
pathFilter() = {{
"test",
"images"},
43 forwardFilter.
basePath() =
"/home/tobias/Pictures";
48 blockFilter.
pathFilter() = {{
"test",
"images"},
52 blockFilter.
status() = 404;
57 blockFilter2.
invert() =
true;
59 blockFilter2.
regexFilter().assign(R
"(/test2?(/images)?(/[A-Za-z0-9_\-]*\.?[A-Za-z]{2,4})?)");
60 blockFilter2.status() = 404;
65 authFilter.
pathFilter() = {{
"test",
"images"}};
66 authFilter.
authName() =
"Not for everyone!";
67 authFilter.
authFunction() = [](
string user,
string password) ->
bool {
68 return (user ==
"test" && password ==
"supersecure");
78 auto& req = connection.
request();
79 auto& session = connection.
session();
87 string encoded = R
"(<input type="text" value="tä𝔸𝔸𝔸st">)";
88 string decoded = R
"(<input type="text" value="tä𝔸𝔸𝔸st">)";
90 resp << "<!DOCTYPE html>\n"
91 "<html><head><title>Test</title></head><body>"
92 "<p>Hello World! HTML string: "
97 << req.env().getRequestPath().size() <<
" elements): "
98 << req.env()[
"REQUEST_URI"] <<
"</p>"
100 << req.env()[
"HTTPS"] <<
"</p>"
102 << req.env()[
"SERVER_NAME"]
104 "<p>Server software: "
105 << req.env()[
"SERVER_SOFTWARE"] <<
"</p>"
107 << req.env()[
"BASE_URL"] <<
"</p>"
108 "<p>Full URL with QS: "
109 << req.env()[
"FULL_URL_WITH_QS"] <<
"</p>"
110 "<p>Full URL without QS: "
111 << req.env()[
"FULL_URL_WITHOUT_QS"] <<
"</p>";
114 auto currentUid = getuid();
115 auto currentGid = getgid();
116 auto currentEUid = geteuid();
117 auto currentEGid = getegid();
118 int groupCount = getgroups(0,
nullptr);
119 resp <<
"<p>Privileges: uid = " << currentUid <<
"; gid = " << currentGid <<
"; euid = "
120 << currentEUid <<
"; egid = " << currentEGid <<
"</p>";
121 vector<gid_t> currentGL(groupCount, 0);
122 if (getgroups(groupCount, ¤tGL[0]) >= 0) {
123 resp <<
"<p>Current groups: ";
124 for (
auto const& e : currentGL) {
131 if (session.isSet(
"test")) {
132 resp <<
"<p>Session available! Value: " << any_cast<string>(session[
"test"])
134 session.invalidate();
136 session.set(
"test",
string(
"and even more blah"));
139 session.set(
"test",
"blah blah blah");
140 resp <<
"<p>There was no session yet, but now there should be one!"
145 if (decoded == encodedDecoded) {
146 resp <<
"<p>yay!</p>";
153 resp <<
"<p>Hello World 2!</p>"
Class for managing sessions and getting and setting connection-independent session data.
This file will be configured by CMake and contains the necessary properties to ensure that a loaded a...
std::vector< BlockFilter > & blockFilters() noexcept
bool & filtersEnabled() noexcept
std::vector< AuthFilter > & authFilters() noexcept
std::vector< ForwardFilter > & forwardFilters() noexcept
std::vector< std::string > & extensionFilter() noexcept
std::regex & regexFilter() noexcept
bool & regexFilterEnabled() noexcept
std::vector< std::vector< std::string > > & pathFilter() noexcept
bool & invertExtensionFilter() noexcept
AccessFilterList & accessFilters()
std::string & authName() noexcept
std::function< bool(std::string, std::string)> & authFunction() noexcept
unsigned int & status() noexcept
nawa::Session & session() noexcept
void setCookiePolicy(Cookie policy)
void setCookie(std::string const &key, Cookie cookie)
std::ostream & responseStream() noexcept
nawa::Request const & request() const noexcept
std::string & basePath() noexcept
std::string start(std::string sessionId, std::optional< unsigned long > keepalive=std::nullopt)
Namespace containing functions for text encoding and decoding.
std::string htmlEncode(std::string input, bool encodeAll=false)
std::string htmlDecode(std::string input)
int handleRequest(Connection &connection)
int init(nawa::AppInit &appInit)