CppServer  1.0.4.0
C++ Server Library
https_server.cpp
Go to the documentation of this file.
1 
10 
11 #include "string/format.h"
12 
13 namespace CppServer {
14 namespace HTTP {
15 
16 void HTTPSServer::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: https_server.h:42
HTTPS server definition.
C++ Server project definitions.
Definition: asio.h:56