CppServer  1.0.4.0
C++ Server Library
http_server.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERVER_HTTP_HTTP_SERVER_H
10 #define CPPSERVER_HTTP_HTTP_SERVER_H
11 
12 #include "http_session.h"
13 
14 #include "cache/filecache.h"
15 #include "server/asio/tcp_server.h"
16 
17 namespace CppServer {
18 namespace HTTP {
19 
21 
30 {
31 public:
32  using TCPServer::TCPServer;
33 
34  HTTPServer(const HTTPServer&) = delete;
35  HTTPServer(HTTPServer&&) = delete;
36  virtual ~HTTPServer() = default;
37 
38  HTTPServer& operator=(const HTTPServer&) = delete;
40 
42  CppCommon::FileCache& cache() noexcept { return _cache; }
43  const CppCommon::FileCache& cache() const noexcept { return _cache; }
44 
46 
51  void AddStaticContent(const CppCommon::Path& path, const std::string& prefix = "/", const CppCommon::Timespan& timeout = CppCommon::Timespan::hours(1));
53 
56  void RemoveStaticContent(const CppCommon::Path& path) { _cache.remove_path(path); }
58  void ClearStaticContent() { _cache.clear(); }
59 
61  void Watchdog(const CppCommon::UtcTimestamp& utc = CppCommon::UtcTimestamp()) { _cache.watchdog(utc); }
62 
63 protected:
64  std::shared_ptr<Asio::TCPSession> CreateSession(const std::shared_ptr<Asio::TCPServer>& server) override { return std::make_shared<HTTPSession>(std::dynamic_pointer_cast<HTTPServer>(server)); }
65 
66 private:
67  // Static content cache
68  CppCommon::FileCache _cache;
69 };
70 
73 } // namespace HTTP
74 } // namespace CppServer
75 
76 #endif // CPPSERVER_HTTP_HTTP_SERVER_H
void AddStaticContent(const CppCommon::Path &path, const std::string &prefix="/", const CppCommon::Timespan &timeout=CppCommon::Timespan::hours(1))
Add static content cache.
Definition: http_server.cpp:16
HTTPServer & operator=(HTTPServer &&)=delete
void ClearStaticContent()
Clear static content cache.
Definition: http_server.h:58
CppCommon::FileCache & cache() noexcept
Get the static content cache.
Definition: http_server.h:42
HTTPServer(HTTPServer &&)=delete
const CppCommon::FileCache & cache() const noexcept
Definition: http_server.h:43
std::shared_ptr< Asio::TCPSession > CreateSession(const std::shared_ptr< Asio::TCPServer > &server) override
Definition: http_server.h:64
HTTPServer & operator=(const HTTPServer &)=delete
virtual ~HTTPServer()=default
HTTPServer(const HTTPServer &)=delete
void Watchdog(const CppCommon::UtcTimestamp &utc=CppCommon::UtcTimestamp())
Watchdog the static content cache.
Definition: http_server.h:61
void RemoveStaticContent(const CppCommon::Path &path)
Remove static content cache.
Definition: http_server.h:56
HTTP session definition.
C++ Server project definitions.
Definition: asio.h:56
TCP server definition.