Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
Public Member Functions | Static Public Member Functions | List of all members
FileHandler Class Reference

this class allow you to set any file of filesystem as response body More...

#include <file_handler.h>

Inheritance diagram for FileHandler:
Inheritance graph
Collaboration diagram for FileHandler:
Collaboration graph

Public Member Functions

 FileHandler (const char *route, const char *filePath, const char *mimeType, bool isBinary)
 
void exec () override
 
- Public Member Functions inherited from Handler
 Handler (const char *route=nullptr, HTTP::Method method=HTTP::Method::ANY, Handler *next=nullptr)
 
virtual ~Handler ()
 
virtual void setNext (Handler *next)
 
virtual void add (Handler *handler)
 
bool isRouted ()
 
std::string getRoute ()
 
HTTP::Method getMethod ()
 
void setContext (Context *context)
 
void handleRequest ()
 

Static Public Member Functions

static bool loadFile (const char *filePath, std::string &data)
 

Additional Inherited Members

- Protected Member Functions inherited from Handler
ContextgetContext ()
 

Detailed Description

this class allow you to set any file of filesystem as response body

FileHandler can handle as text files (like css, js), as binary data (img, png others)

Constructor & Destructor Documentation

FileHandler::FileHandler ( const char *  route,
const char *  filePath,
const char *  mimeType,
bool  isBinary 
)

create file handlers with specified uri route, file path, content type etc.

Parameters
routeuri route file
filePathlocal file path
mimeTypecontent type
isBinaryif file is binary, set true, false if it's text.

Member Function Documentation

void FileHandler::exec ( )
overridevirtual

make http body of response object as file in filePath

Implements Handler.

static bool FileHandler::loadFile ( const char *  filePath,
std::string &  data 
)
static

static function that read all data from file to string

Parameters
filePathpath to file
dataout param, if can read file, it will be written to data,do nothing otherwise
Returns
true, if read successfully, false otherwise

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