37 auto& req = connection.
request();
38 auto& session = connection.
session();
42 if (req.get().count(
"download") == 1 && session.isSet(req.get()[
"download"])) {
44 auto downloadFile = any_cast<File const>(session[req.get()[
"download"]]);
45 connection.
setHeader(
"content-type", downloadFile.contentType());
46 connection.
setHeader(
"content-disposition",
"attachment; filename=\"" + downloadFile.filename() +
"\"");
47 connection.
setHeader(
"content-length", to_string(downloadFile.size()));
50 }
catch (bad_any_cast
const& e) {
51 resp <<
"Bad any cast: " << e.what();
56 resp <<
"<!DOCTYPE html>\n"
57 "<html><head><title>NAWA GPC Test</title></head><body>\n";
59 auto printEncoded = [&](
string const& k,
string const& v) {
64 resp <<
"<p>COOKIE vars:</p><ul>";
65 for (
auto const& [k, v] : req.cookie()) {
72 resp <<
"<p>GET vars:</p><ul>";
73 for (
auto const& [k, v] : req.get()) {
80 resp <<
"<p>POST vars (without files):</p><ul>";
81 for (
auto const& [k, v] : req.post()) {
87 if (req.post().hasFiles()) {
88 resp <<
"<p>POST files:</p><ul>";
89 for (
auto const& [k, v] : req.post().getFileMultimap()) {
100 <<
"; content type: "
106 session.set(v.filename(), v);
111 if (req.post().getRaw()) {
112 resp <<
"<p>Raw POST data:</p><pre>" << *req.post().getRaw() <<
"</pre>";
115 resp << R
"(<p>Some POST form:</p><form name="testform" method="post" action="?" enctype="multipart/form-data">)"
116 << R"(<p>Field one (1): <input type="text" name="one"></p>)"
117 << R"(<p>Field one (2): <input type="text" name="one"></p>)"
118 << R"(<p>Field two: <input type="text" name="two"></p>)"
119 << R"(<p>Field fileupload (1): <input type="file" name="fileupload"></p>)"
120 << R"(<p>Field fileupload (2): <input type="file" name="fileupload"></p>)"
121 << R"(<p><input type="submit" value="Go" name="submit"></p></form>)";
This file will be configured by CMake and contains the necessary properties to ensure that a loaded a...
nawa::Session & session() noexcept
void setHeader(std::string key, std::string value)
std::ostream & responseStream() noexcept
nawa::Request const & request() const noexcept
void setResponseBody(std::string content)
std::string start(std::string sessionId, std::optional< unsigned long > keepalive=std::nullopt)
Namespace containing functions for text encoding and decoding.
int handleRequest(Connection &connection)
int init(AppInit &appInit)
std::string urlEncode(std::string const &input)
std::string htmlEncode(std::string input, bool encodeAll=false)