SNode.C
Loading...
Searching...
No Matches
StaticMiddleware.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef EXPRESS_MIDDLEWARE_STATICMIDDLEWARE_H
21#define EXPRESS_MIDDLEWARE_STATICMIDDLEWARE_H
22
23#include "express/Router.h" // IWYU pragma: export
24#include "web/http/ConnectionState.h" // IWYU pragma: export
25#include "web/http/CookieOptions.h"
26
27#ifndef DOXYGEN_SHOULD_SKIP_THIS
28
29#include <map>
30#include <string>
31#include <utility>
32
33#endif /* DOXYGEN_SHOULD_SKIP_THIS */
34
35namespace express::middleware {
36
37 class StaticMiddleware : public Router {
38 public:
40
42
43 protected:
44 explicit StaticMiddleware(const std::string& root);
45 static class StaticMiddleware& instance(const std::string& root);
46
47 public:
51 StaticMiddleware& appendStdHeaders(const std::string& field, const std::string& value);
53 appendStdCookie(const std::string& name, const std::string& value, const std::map<std::string, std::string>& options = {});
54 StaticMiddleware& afterResponse(web::http::ConnectionState connectionState);
55
56 private:
58 std::map<std::string, std::string> stdHeaders = {{"Cache-Control", "public, max-age=0"}, {"Accept-Ranges", "bytes"}};
61
62 friend class StaticMiddleware& StaticMiddleware(const std::string& root);
63 };
64
65 class StaticMiddleware& StaticMiddleware(const std::string& root);
66
67} // namespace express::middleware
68
69#endif // EXPRESS_MIDDLEWARE_STATICMIDDLEWARE_H
StaticMiddleware & appendStdHeaders(const std::string &field, const std::string &value)
web::http::ConnectionState defaultConnectionState
StaticMiddleware(const StaticMiddleware &)=delete
StaticMiddleware & setStdHeaders(const std::map< std::string, std::string > &stdHeaders)
StaticMiddleware & operator=(const StaticMiddleware &)=delete
static class StaticMiddleware & instance(const std::string &root)
StaticMiddleware & appendStdCookie(const std::string &name, const std::string &value, const std::map< std::string, std::string > &options={})
StaticMiddleware & appendStdHeaders(const std::map< std::string, std::string > &stdHeaders)
StaticMiddleware(const std::string &root)
StaticMiddleware & afterResponse(web::http::ConnectionState connectionState)
int main(int argc, char *argv[])
#define QUOTE_INCLUDE(a)
Definition clients.h:25
#define STR_INCLUDE(a)
Definition servers.h:26
static express::Router getRouter()
Definition servers.h:46
static WebApp getWebApp(const std::string &name)
Definition servers.h:57
static WebApp getWebApp(const std::string &name)
Definition servers.h:74