HttpWebApp.hpp
Go to the documentation of this file.
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_SERVER__HTTP_WEB_APPLICATION
18 #define COM_BORA_SOFTWARE__BALAU_NETWORK_SERVER__HTTP_WEB_APPLICATION
19 
21 #include <Balau/Network/Http/Server/Impl/HttpWebAppFactory.hpp>
22 
23 namespace Balau::Network::Http {
24 
25 class HttpSession;
26 
39 class HttpWebApp {
46  public: template <typename WebAppT> static void registerHttpWebApp(const std::string & name) {
47  Impl::HttpWebAppFactory::registerHttpWebApp<WebAppT>(name);
48  }
49 
51 
53 
57  public: static StringResponse createOkResponse(HttpSession & session, const StringRequest & request);
58 
62  public: static EmptyResponse createOkHeadResponse(HttpSession & session, const StringRequest & request);
63 
65 
69  public: static EmptyResponse createRedirectResponse(HttpSession & session, const StringRequest & request, std::string_view location);
70 
74  public: static EmptyResponse createPermanentRedirectResponse(HttpSession & session, const StringRequest & request, std::string_view location);
75 
77 
81  public: static StringResponse createBadRequestResponse(HttpSession & session, const StringRequest & request, std::string_view errorMessage);
82 
86  public: static EmptyResponse createBadRequestHeadResponse(HttpSession & session, const StringRequest & request);
87 
91  static StringResponse createNotFoundStringResponse(HttpSession & session, const StringRequest & request);
92 
96  static EmptyResponse createNotFoundHeadResponse(HttpSession & session, const StringRequest & request);
97 
99 
103  public: static StringResponse createServerErrorResponse(HttpSession & session, const StringRequest & request, std::string_view errorMessage);
104 
108  public: static EmptyResponse createServerErrorHeadResponse(HttpSession & session, const StringRequest & request);
109 
111 
121  public: virtual void handleGetRequest(HttpSession & session,
122  const StringRequest & request,
123  std::map<std::string, std::string> & variables) = 0;
124 
134  public: virtual void handleHeadRequest(HttpSession & session,
135  const StringRequest & request,
136  std::map<std::string, std::string> & variables) = 0;
137 
147  public: virtual void handlePostRequest(HttpSession & session,
148  const StringRequest & request,
149  std::map<std::string, std::string> & variables) = 0;
150 
152 
156  public: virtual ~HttpWebApp() = default;
157 };
158 
159 } // namespace Balau::Network::Http
160 
161 #endif // COM_BORA_SOFTWARE__BALAU_NETWORK_SERVER__HTTP_WEB_APPLICATION
Components and utilities working on HTTP data transmission.
Definition: HttpClient.hpp:26
static StringResponse createBadRequestResponse(HttpSession &session, const StringRequest &request, std::string_view errorMessage)
Create a bad request response.
virtual void handleGetRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables)=0
Handle a GET request.
virtual void handlePostRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables)=0
Handle a POST request.
static EmptyResponse createOkHeadResponse(HttpSession &session, const StringRequest &request)
Create an empty 200 response for a head request.
Manages the handling of HTTP messages and WebSocket upgrade requests in an HTTP connection.
Definition: HttpSession.hpp:46
Low level types used in networking code.
static EmptyResponse createNotFoundHeadResponse(HttpSession &session, const StringRequest &request)
Create a not found response for a head request.
virtual ~HttpWebApp()=default
Destroy the HTTP web application instance.
static EmptyResponse createBadRequestHeadResponse(HttpSession &session, const StringRequest &request)
Create a bad request response for a head request.
static void registerHttpWebApp(const std::string &name)
Register an HTTP web application.
Definition: HttpWebApp.hpp:46
Abstract base class of HTTP web application handlers.
Definition: HttpWebApp.hpp:39
Response< EmptyBody > EmptyResponse
A response with an empty body.
Definition: NetworkTypes.hpp:293
Response< StringBody > StringResponse
A response with a string body.
Definition: NetworkTypes.hpp:283
Request< StringBody > StringRequest
A request with a string body.
Definition: NetworkTypes.hpp:267
static EmptyResponse createPermanentRedirectResponse(HttpSession &session, const StringRequest &request, std::string_view location)
Create a permanent redirect response.
static StringResponse createOkResponse(HttpSession &session, const StringRequest &request)
Create an empty 200 response.
static StringResponse createServerErrorResponse(HttpSession &session, const StringRequest &request, std::string_view errorMessage)
Create a server error response.
static EmptyResponse createRedirectResponse(HttpSession &session, const StringRequest &request, std::string_view location)
Create a redirect response.
virtual void handleHeadRequest(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables)=0
Handle a HEAD request.
static StringResponse createNotFoundStringResponse(HttpSession &session, const StringRequest &request)
Create a not found response.
static EmptyResponse createServerErrorHeadResponse(HttpSession &session, const StringRequest &request)
Create a server error response for a head request.