An HTTP web application handler that sends an email when a post request is made. More...
#include <EmailSendingHttpWebApp.hpp>
Public Types | |
using | BodyGenerator = std::function< std::string(HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables, const ParameterMap &)> |
The type of the body generator function. More... | |
using | ParameterMap = std::unordered_map< std::string, std::string > |
The map type that holds request body parameters. More... | |
Public Member Functions | |
EmailSendingHttpWebApp (BodyGenerator bodyGenerator_, std::shared_ptr< HttpWebApp > successHandler_, std::shared_ptr< HttpWebApp > failureHandler_, std::string host, unsigned short port, std::string user, std::string pw, std::string userAgent, std::string subject_, std::string from_, std::string to_, std::vector< std::string > cc_={}, bool useTLS_=true) | |
Construct an email sender handler with success/failure handlers. More... | |
EmailSendingHttpWebApp (BodyGenerator bodyGenerator_, std::string successRedirectLocation_, std::string failureRedirectLocation_, std::string host, unsigned short port, std::string user, std::string pw, std::string userAgent, std::string subject_, std::string from_, std::string to_, std::vector< std::string > cc_={}, bool useTLS_=true) | |
Construct an email sender handler with success/failure redirects. More... | |
EmailSendingHttpWebApp (const EnvironmentProperties &configuration, const BalauLogger &logger) | |
Constructor called by the HTTP server during construction. More... | |
void | handleGetRequest (HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override |
Handle a GET request. More... | |
void | handleHeadRequest (HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override |
Handle a HEAD request. More... | |
void | handlePostRequest (HttpSession &session, const StringRequest &request, std::map< std::string, std::string > &variables) override |
Handle a POST request. More... | |
Public Member Functions inherited from HttpWebApp | |
virtual | ~HttpWebApp ()=default |
Destroy the HTTP web application instance. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from HttpWebApp | |
static EmptyResponse | createBadRequestHeadResponse (HttpSession &session, const StringRequest &request) |
Create a bad request response for a head request. More... | |
static StringResponse | createBadRequestResponse (HttpSession &session, const StringRequest &request, std::string_view errorMessage) |
Create a bad request response. More... | |
static EmptyResponse | createNotFoundHeadResponse (HttpSession &session, const StringRequest &request) |
Create a not found response for a head request. More... | |
static StringResponse | createNotFoundStringResponse (HttpSession &session, const StringRequest &request) |
Create a not found response. More... | |
static EmptyResponse | createOkHeadResponse (HttpSession &session, const StringRequest &request) |
Create an empty 200 response for a head request. More... | |
static StringResponse | createOkResponse (HttpSession &session, const StringRequest &request) |
Create an empty 200 response. More... | |
static EmptyResponse | createPermanentRedirectResponse (HttpSession &session, const StringRequest &request, std::string_view location) |
Create a permanent redirect response. More... | |
static EmptyResponse | createRedirectResponse (HttpSession &session, const StringRequest &request, std::string_view location) |
Create a redirect response. More... | |
static EmptyResponse | createServerErrorHeadResponse (HttpSession &session, const StringRequest &request) |
Create a server error response for a head request. More... | |
static StringResponse | createServerErrorResponse (HttpSession &session, const StringRequest &request, std::string_view errorMessage) |
Create a server error response. More... | |
template<typename WebAppT > | |
static void | registerHttpWebApp (const std::string &name) |
Register an HTTP web application. More... | |
An HTTP web application handler that sends an email when a post request is made.
The get and head request handler methods will result in bad requests.
Before using an email sending handler, a translator function that maps between the request parameters and the email body to be sent by the email sender is required. This function is supplied to the handler constructor, and may be provided via a lambda expression.
The request parameters originate from the calling client, and their nature is determined by the web application. These must be translated into a body message that will be sent by the email sending handler.
using BodyGenerator = std::function<std::string (HttpSession & session, const StringRequest & request, std::map<std::string, std::string> & variables, const ParameterMap &)> |
The type of the body generator function.
using ParameterMap = std::unordered_map<std::string, std::string> |
The map type that holds request body parameters.
These are extracted from the POST request body, and the body generator function supplied to the constructor is called to translate them into the email body to be sent.
EmailSendingHttpWebApp | ( | BodyGenerator | bodyGenerator_, |
std::shared_ptr< HttpWebApp > | successHandler_, | ||
std::shared_ptr< HttpWebApp > | failureHandler_, | ||
std::string | host, | ||
unsigned short | port, | ||
std::string | user, | ||
std::string | pw, | ||
std::string | userAgent, | ||
std::string | subject_, | ||
std::string | from_, | ||
std::string | to_, | ||
std::vector< std::string > | cc_ = {} , |
||
bool | useTLS_ = true |
||
) |
Construct an email sender handler with success/failure handlers.
The email handler is created by supplying the destination details and two response handlers, one for successful emailings and another for failed emailings.
One of the get request methods of the two handlers will be called after email processing has succeeded or failed.
EmailSendingHttpWebApp | ( | BodyGenerator | bodyGenerator_, |
std::string | successRedirectLocation_, | ||
std::string | failureRedirectLocation_, | ||
std::string | host, | ||
unsigned short | port, | ||
std::string | user, | ||
std::string | pw, | ||
std::string | userAgent, | ||
std::string | subject_, | ||
std::string | from_, | ||
std::string | to_, | ||
std::vector< std::string > | cc_ = {} , |
||
bool | useTLS_ = true |
||
) |
Construct an email sender handler with success/failure redirects.
The email handler is created by supplying the destination details and two response handlers, one for successful emailings and another for failed emailings.
One of the get request methods of the two handlers will be called after email processing has succeeded or failed.
EmailSendingHttpWebApp | ( | const EnvironmentProperties & | configuration, |
const BalauLogger & | logger | ||
) |
Constructor called by the HTTP server during construction.
configuration | The environment configuration for the email sender. |
|
overridevirtual |
Handle a GET request.
The supplied session provides shared server state and the sendResponse method.
session | the HTTP session object, also containing the client session |
request | the HTTP request object |
variables | the request variables that are generated and consumed during the request |
Implements HttpWebApp.
|
overridevirtual |
Handle a HEAD request.
The supplied session provides shared server state and the sendResponse method.
session | the HTTP session object, also containing the client session |
request | the HTTP request object |
variables | the request variables that are generated and consumed during the request |
Implements HttpWebApp.
|
overridevirtual |
Handle a POST request.
The supplied session provides shared server state and the sendResponse method.
session | the HTTP session object, also containing the client session |
request | the HTTP request object |
variables | the request variables that are generated and consumed during the request |
Implements HttpWebApp.