CppServer 1.0.5.0
C++ Server Library
Loading...
Searching...
No Matches
http_server.cpp
Go to the documentation of this file.
1
10
11#include "string/format.h"
12
13namespace CppServer {
14namespace HTTP {
15
16void HTTPServer::AddStaticContent(const CppCommon::Path& path, const std::string& prefix, const CppCommon::Timespan& timeout)
17{
18 auto hanlder = [](CppCommon::FileCache & cache, const std::string& key, const std::string& value, const CppCommon::Timespan& timespan)
19 {
20 auto response = HTTPResponse();
21 response.SetBegin(200);
22 response.SetContentType(CppCommon::Path(key).extension().string());
23 response.SetHeader("Cache-Control", CppCommon::format("max-age={}", timespan.seconds()));
24 response.SetBody(value);
25 return cache.insert(key, response.cache(), timespan);
26 };
27
28 cache().insert_path(path, prefix, timeout, hanlder);
29}
30
31} // namespace HTTP
32} // namespace CppServer
void AddStaticContent(const CppCommon::Path &path, const std::string &prefix="/", const CppCommon::Timespan &timeout=CppCommon::Timespan::hours(1))
Add static content cache.
CppCommon::FileCache & cache() noexcept
Get the static content cache.
Definition http_server.h:42
HTTP server definition.
C++ Server project definitions.
Definition asio.h:56