2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#include "express/middleware/StaticMiddleware.h"
44#include "core/socket/stream/SocketConnection.h"
45#include "web/http/server/SocketContext.h"
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
49#include "log/Logger.h"
59 ,
index(
"index.html") {
63 [&stdHeaders =
this->stdHeaders, &stdCookies =
this->stdCookies, &connectionState
= this->defaultConnectionState]
MIDDLEWARE(
67 if (req->
method ==
"GET") {
69 res->
set("Connection", "close");
71 res->
set("Connection", "keep-alive");
75 for (
auto& [value, options] : stdCookies) {
84 if (req->
url.ends_with(
"/")) {
87 <<
" Express StaticMiddleware Redirecting: " << req->
url <<
" -> " << req->
url + index;
97 const bool fileAllowed =
true;
103 <<
" Express StaticMiddleware: GET " << req->
url +
" -> " << root + req->
url;
106 <<
" Express StaticMiddleware " << req->
url +
" -> " << root + req->
url;
136 this->stdHeaders.insert(stdHeaders.begin(), stdHeaders.end());
148 const std::string& value,
149 const std::map<std::string, std::string>& options) {
163 static std::map<
const std::string, std::shared_ptr<
class StaticMiddleware>> staticMiddlewares;
165 if (!staticMiddlewares.contains(root)) {
169 return *staticMiddlewares[root];
#define MIDDLEWARE(req, res, next)
const std::string & getConnectionName() const
SocketConnection * getSocketConnection() const
void operator()(const std::string &how="") const
Response & cookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
void redirect(int state, const std::string &loc, const std::string &html={})
void sendFile(const std::string &file, const std::function< void(int)> &callback)
void sendStatus(int state, const std::string &html={})
Response & set(const std::string &field, const std::string &value, bool overwrite=true)
void send(const std::string &chunk)
Response & status(int status)
Response & set(const std::map< std::string, std::string > &headers, bool overwrite=true)
web::http::server::SocketContext * getSocketContext() const
const Router & setStrictRouting(bool strictRouting=true) const
std::map< std::string, web::http::CookieOptions > stdCookies
web::http::ConnectionState defaultConnectionState
StaticMiddleware & clearStdHeaders()
std::map< std::string, std::string > stdHeaders
StaticMiddleware & afterResponse(web::http::ConnectionState connectionState)
const std::map< std::string, std::string > & getOptions() const
CookieOptions(const std::string &value, const std::map< std::string, std::string > &options)
const std::string & getValue() const