WebFramework v3.0.12
Web framework for C++.
Loading...
Searching...
No Matches
framework::ResourceExecutor Class Reference

Used for sending asset files. More...

#include <ResourceExecutor.h>

Inheritance diagram for framework::ResourceExecutor:
framework::interfaces::IStaticFile framework::interfaces::IDynamicFile framework::BaseStatelessExecutor framework::interfaces::IFile framework::interfaces::IFile framework::BaseExecutor

Public Member Functions

 ResourceExecutor (const json::JSONParser &configuration, const std::filesystem::path &assets, uint64_t cachingSize, const std::filesystem::path &pathToTemplates)
 
void init (const utility::JSONSettingsParser::ExecutorSettings &settings) override
 Create assets folder.
 
void sendStaticFile (const std::string &filePath, HTTPResponse &response, bool isBinary=true, const std::string &fileName="") override
 Override from IStaticFile interface.
 
void sendDynamicFile (const std::string &filePath, HTTPResponse &response, const std::unordered_map< std::string, std::string > &variables={}, bool isBinary=true, const std::string &fileName="") override
 Override from IDynamicFile interface.
 
void registerDynamicFunction (const std::string &functionName, std::function< std::string(const std::vector< std::string > &)> &&function) override
 Add new function in .wfdp interpreter.
 
void unregisterDynamicFunction (const std::string &functionName) override
 Remove function from .wfdp interpreter.
 
bool isDynamicFunctionRegistered (const std::string &functionName) override
 Check if function is registered.
 
void doGet (HTTPRequest &request, HTTPResponse &response) override
 Send file via GET request.
 
void doPost (HTTPRequest &request, HTTPResponse &response) override
 Send file via POST request.
 
const std::filesystem::path & getPathToAssets () const final override
 
void notFoundError (HTTPResponse &response, const std::exception *exception)
 Send 404.html from WebFrameworkAssets.
 
void badRequestError (HTTPResponse &response, const std::exception *exception)
 Send 400.html from WebFrameworkAssets.
 
void internalServerError (HTTPResponse &response, const std::exception *exception)
 Send 500.html from WebFrameworkAssets.
 
bool getIsCaching () const
 
- Public Member Functions inherited from framework::interfaces::IStaticFile
- Public Member Functions inherited from framework::interfaces::IFile
- Public Member Functions inherited from framework::interfaces::IDynamicFile
- Public Member Functions inherited from framework::BaseStatelessExecutor
virtual executorType getType () const final override
 Get executor type.
 
virtual void destroy () final override
 Stateless executors can't call destroy method.
 
- Public Member Functions inherited from framework::BaseExecutor
virtual void doHead (HTTPRequest &request, HTTPResponse &response)
 Process HEAD request.
 
virtual void doPut (HTTPRequest &request, HTTPResponse &response)
 Process PUT request.
 
virtual void doDelete (HTTPRequest &request, HTTPResponse &response)
 Process DELETE request.
 
virtual void doPatch (HTTPRequest &request, HTTPResponse &response)
 Process PATCH request.
 
virtual void doOptions (HTTPRequest &request, HTTPResponse &response)
 Process OPTIONS request.
 
virtual void doTrace (HTTPRequest &request, HTTPResponse &response)
 Process TRACE request.
 
virtual void doConnect (HTTPRequest &request, HTTPResponse &response)
 Process CONNECT request.
 

Additional Inherited Members

- Public Types inherited from framework::BaseExecutor
enum class  executorType {
  none , stateful , stateless , heavyOperationStateful ,
  heavyOperationStateless
}
 

Detailed Description

Used for sending asset files.

Definition at line 17 of file ResourceExecutor.h.

Constructor & Destructor Documentation

◆ ResourceExecutor()

framework::ResourceExecutor::ResourceExecutor ( const json::JSONParser & configuration,
const std::filesystem::path & assets,
uint64_t cachingSize,
const std::filesystem::path & pathToTemplates )

Definition at line 54 of file ResourceExecutor.cpp.

Member Function Documentation

◆ badRequestError()

void framework::ResourceExecutor::badRequestError ( HTTPResponse & response,
const std::exception * exception )

Send 400.html from WebFrameworkAssets.

Parameters
responseresponse with error file

Definition at line 189 of file ResourceExecutor.cpp.

◆ doGet()

void framework::ResourceExecutor::doGet ( HTTPRequest & request,
HTTPResponse & response )
overridevirtual

Send file via GET request.

Parameters
requestfile request
responseresponse with asset file
Exceptions
framework::exceptions::NotImplementedException

Reimplemented from framework::BaseExecutor.

Definition at line 154 of file ResourceExecutor.cpp.

◆ doPost()

void framework::ResourceExecutor::doPost ( HTTPRequest & request,
HTTPResponse & response )
overridevirtual

Send file via POST request.

Parameters
requestfile request
responseresponse with asset file

Reimplemented from framework::BaseExecutor.

Definition at line 159 of file ResourceExecutor.cpp.

◆ getIsCaching()

bool framework::ResourceExecutor::getIsCaching ( ) const

Definition at line 229 of file ResourceExecutor.cpp.

◆ getPathToAssets()

const filesystem::path & framework::ResourceExecutor::getPathToAssets ( ) const
finaloverridevirtual

Implements framework::interfaces::IFile.

Definition at line 164 of file ResourceExecutor.cpp.

◆ init()

void framework::ResourceExecutor::init ( const utility::JSONSettingsParser::ExecutorSettings & settings)
overridevirtual

Create assets folder.

Parameters
settingsnot used

Reimplemented from framework::BaseExecutor.

Definition at line 68 of file ResourceExecutor.cpp.

◆ internalServerError()

void framework::ResourceExecutor::internalServerError ( HTTPResponse & response,
const std::exception * exception )

Send 500.html from WebFrameworkAssets.

Parameters
responseresponse with error file

Definition at line 209 of file ResourceExecutor.cpp.

◆ isDynamicFunctionRegistered()

bool framework::ResourceExecutor::isDynamicFunctionRegistered ( const std::string & functionName)
overridevirtual

Check if function is registered.

Parameters
functionNameName of function
Returns
true if function is registered, false otherwise

Implements framework::interfaces::IDynamicFile.

Definition at line 149 of file ResourceExecutor.cpp.

◆ notFoundError()

void framework::ResourceExecutor::notFoundError ( HTTPResponse & response,
const std::exception * exception )

Send 404.html from WebFrameworkAssets.

Parameters
responseresponse with error file

Definition at line 169 of file ResourceExecutor.cpp.

◆ registerDynamicFunction()

void framework::ResourceExecutor::registerDynamicFunction ( const std::string & functionName,
std::function< std::string(const std::vector< std::string > &)> && function )
overridevirtual

Add new function in .wfdp interpreter.

Parameters
functionNameName of new function
functionFunction implementation

Implements framework::interfaces::IDynamicFile.

Definition at line 139 of file ResourceExecutor.cpp.

◆ sendDynamicFile()

void framework::ResourceExecutor::sendDynamicFile ( const std::string & filePath,
HTTPResponse & response,
const std::unordered_map< std::string, std::string > & variables = {},
bool isBinary = true,
const std::string & fileName = "" )
overridevirtual

Override from IDynamicFile interface.

Parameters
filePathpath to file from assets folder
responseused for sending file
Exceptions
file_manager::exceptions::FileDoesNotExistException

Implements framework::interfaces::IDynamicFile.

Definition at line 110 of file ResourceExecutor.cpp.

◆ sendStaticFile()

void framework::ResourceExecutor::sendStaticFile ( const std::string & filePath,
HTTPResponse & response,
bool isBinary = true,
const std::string & fileName = "" )
overridevirtual

Override from IStaticFile interface.

Parameters
filePathpath to file from assets folder
responseused for sending file
Exceptions
file_manager::exceptions::FileDoesNotExistException

Implements framework::interfaces::IStaticFile.

Definition at line 83 of file ResourceExecutor.cpp.

◆ unregisterDynamicFunction()

void framework::ResourceExecutor::unregisterDynamicFunction ( const std::string & functionName)
overridevirtual

Remove function from .wfdp interpreter.

Parameters
functionNameName of function

Implements framework::interfaces::IDynamicFile.

Definition at line 144 of file ResourceExecutor.cpp.


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