Public Member Functions | List of all members
CannedHttpWebApp Class Reference

An HTTP web application handler that serves a fixed response for each request method. More...

#include <CannedHttpWebApp.hpp>

Inheritance diagram for CannedHttpWebApp:
[legend]
Collaboration diagram for CannedHttpWebApp:
[legend]

Public Member Functions

 CannedHttpWebApp (std::string mimeType_, std::string getResponseBody_, std::string postResponseBody_)
 Create a canned handler that has get and post method bodies. More...
 
 CannedHttpWebApp (const EnvironmentProperties &configuration, const BalauLogger &logger)
 Constructor used by the HTTP server. 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...
 

Detailed Description

An HTTP web application handler that serves a fixed response for each request method.

Constructor & Destructor Documentation

◆ CannedHttpWebApp() [1/2]

CannedHttpWebApp ( std::string  mimeType_,
std::string  getResponseBody_,
std::string  postResponseBody_ 
)

Create a canned handler that has get and post method bodies.

If a get only or post only canned handler is required, pass the empty string to the get or post response body string.

Any empty bodied get/post body strings will result in bad requests for the respective methods.

Parameters
mimeType_the mime type to be returned in responses
getResponseBody_the response body to send or get requests
postResponseBody_the response body to send or post requests

◆ CannedHttpWebApp() [2/2]

CannedHttpWebApp ( const EnvironmentProperties configuration,
const BalauLogger &  logger 
)

Constructor used by the HTTP server.

Member Function Documentation

◆ handleGetRequest()

void handleGetRequest ( HttpSession session,
const StringRequest request,
std::map< std::string, std::string > &  variables 
)
overridevirtual

Handle a GET request.

The supplied session provides shared server state and the sendResponse method.

Parameters
sessionthe HTTP session object, also containing the client session
requestthe HTTP request object
variablesthe request variables that are generated and consumed during the request

Implements HttpWebApp.

◆ handleHeadRequest()

void handleHeadRequest ( HttpSession session,
const StringRequest request,
std::map< std::string, std::string > &  variables 
)
overridevirtual

Handle a HEAD request.

The supplied session provides shared server state and the sendResponse method.

Parameters
sessionthe HTTP session object, also containing the client session
requestthe HTTP request object
variablesthe request variables that are generated and consumed during the request

Implements HttpWebApp.

◆ handlePostRequest()

void handlePostRequest ( HttpSession session,
const StringRequest request,
std::map< std::string, std::string > &  variables 
)
overridevirtual

Handle a POST request.

The supplied session provides shared server state and the sendResponse method.

Parameters
sessionthe HTTP session object, also containing the client session
requestthe HTTP request object
variablesthe request variables that are generated and consumed during the request

Implements HttpWebApp.


The documentation for this class was generated from the following file: