FileServingHttpWebApp.hpp
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2017 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__FILE_SERVING_HTTP_WEB_APP
18 #define COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__FILE_SERVING_HTTP_WEB_APP
19 
21 
22 namespace Balau {
23 
24 class BalauLogger;
25 class EnvironmentProperties;
26 
27 namespace Network::Http::HttpWebApps {
28 
39  public: explicit FileServingHttpWebApp(Resource::File documentRoot_, std::string defaultFile_ = "index.html");
40 
46  public: FileServingHttpWebApp(const EnvironmentProperties & configuration, const BalauLogger & logger);
47 
48  public: void handleGetRequest(HttpSession & session,
49  const StringRequest & request,
50  std::map<std::string, std::string> & variables) override;
51 
52  public: void handleHeadRequest(HttpSession & session,
53  const StringRequest & request,
54  std::map<std::string, std::string> & variables) override;
55 
56  public: void handlePostRequest(HttpSession & session,
57  const StringRequest & request,
58  std::map<std::string, std::string> & variables) override;
59 
61 
62  private: Resource::File resolvePath(HttpSession & session, const StringRequest & request);
63 
64  private: FileBodyValue getBody(HttpSession & session, const StringRequest & request, const std::string & pathStr);
65 
66  private: const Resource::File documentRoot;
67  private: const std::string defaultFile;
68 };
69 
70 } // namespace HttpWebApps::Http::Network
71 
72 } // namespace Balau
73 
74 #endif // COM_BORA_SOFTWARE__BALAU_NETWORK_HTTP_SERVER_HTTP_WEB_APPS__FILE_SERVING_HTTP_WEB_APP
Manages the handling of HTTP messages and WebSocket upgrade requests in an HTTP connection.
Definition: HttpSession.hpp:46
FileServingHttpWebApp(Resource::File documentRoot_, std::string defaultFile_="index.html")
Construct a file serving web application.
void handleGetRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a GET request.
The root Balau namespace.
Definition: ApplicationConfiguration.hpp:23
A hierarchical environment properties holder created from a composite property.
Definition: EnvironmentProperties.hpp:59
Abstract base class of HTTP web application handlers.
Definition: HttpWebApp.hpp:39
An HTTP web application handler that serve files from the file system.
Definition: FileServingHttpWebApp.hpp:32
Abstract base class of HTTP web application handlers.
Request< StringBody > StringRequest
A request with a string body.
Definition: NetworkTypes.hpp:267
void handlePostRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a POST request.
A file on the local file system.
Definition: File.hpp:35
void handleHeadRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override
Handle a HEAD request.
FileBody::value_type FileBodyValue
The type of the message body represented by a file on the filesystem.
Definition: NetworkTypes.hpp:251