Giri's C++ Support Library
C++ library providing everything you need to quickly create awesome applications.
giri::HTTPSession Class Reference

Class representing one session/connection. More...

#include <HTTPServer.h>

Inheritance diagram for giri::HTTPSession:
Collaboration diagram for giri::HTTPSession:

Public Types

using SPtr = std::shared_ptr< HTTPSession >
 
using UPtr = std::unique_ptr< HTTPSession >
 
using WPtr = std::weak_ptr< HTTPSession >
 
- Public Types inherited from giri::Object< T >
using SPtr = std::shared_ptr< T >
 
using UPtr = std::unique_ptr< T >
 
using WPtr = std::weak_ptr< T >
 

Public Member Functions

 HTTPSession (tcp::socket socket, const std::filesystem::path &docRoot, const std::map< std::string, std::string > &mimeTypes, const std::string &indexFile, const std::string &serverString, bool ssl, const std::filesystem::path &cert, const std::filesystem::path &key, boost::asio::io_context &ioc)
 
void run ()
 
bool getSSL () const
 
boost::system::error_code getError () const
 
std::string getClientIP () const
 
std::string getClientPort () const
 
http::request< http::string_body > getRequest () const
 
http::response< http::vector_body< char > > getResult () const
 
std::filesystem::path getDocRoot () const
 
std::string getIndexFile () const
 
std::string getServerString () const
 
std::map< std::string, std::string > getMimeTypes () const
 
void setResult (const http::response< http::vector_body< char >> &res)
 
void setDocRoot (const std::filesystem::path &path)
 
void setIndexFile (const std::string &indx)
 
void setServerString (const std::string &servstr)
 
void addMimeTypes (const std::map< std::string, std::string > &mimeTypes)
 
void close ()
 
- Public Member Functions inherited from giri::Observable< HTTPSession >
void subscribe (const std::weak_ptr< Observer< HTTPSession > > &obs)
 
void unsubscribe (const std::weak_ptr< Observer< HTTPSession > > &obs)
 
void unsubscribeAll ()
 
void notify ()
 

Detailed Description

Class representing one session/connection.

Created by the server when accepting a client connection.

Constructor & Destructor Documentation

◆ HTTPSession()

giri::HTTPSession::HTTPSession ( tcp::socket  socket,
const std::filesystem::path &  docRoot,
const std::map< std::string, std::string > &  mimeTypes,
const std::string &  indexFile,
const std::string &  serverString,
bool  ssl,
const std::filesystem::path &  cert,
const std::filesystem::path &  key,
boost::asio::io_context &  ioc 
)
inlineexplicit

WebSocketSession constructor

Parameters
socketSocket to use.
docRootFolder to serve via http (defaults to "./")
mimeTypesMapping containing additional mimetypes. (will be appended to a set of default mimetypes, overrides existing defaults)
indexFileIndex file to use if no file was provided by request. (defaults to "index.html")
serverStringServer string to be added to the http answers. (defaults to "giris_supportlib_http_server")
ssltrue if ssl should be enabled, false otherwise.
certIf ssl is true, path to certificate file in *.pem format.
keyIf ssl is true path to private key file in *pem format.
iocI/O context which should be used.

Member Function Documentation

◆ addMimeTypes()

void giri::HTTPSession::addMimeTypes ( const std::map< std::string, std::string > &  mimeTypes)
inline

Add additional mimetypes. Only affects new requests within this HTTPSession.

Parameters
mimeTypesAdditional mimetypes to add.

◆ close()

void giri::HTTPSession::close ( )
inline

Close http session.

◆ getClientIP()

std::string giri::HTTPSession::getClientIP ( ) const
inline
Returns
IP of connected client.

◆ getClientPort()

std::string giri::HTTPSession::getClientPort ( ) const
inline
Returns
Port of connected client.

◆ getDocRoot()

std::filesystem::path giri::HTTPSession::getDocRoot ( ) const
inline
Returns
Folder which is served via http.

◆ getError()

boost::system::error_code giri::HTTPSession::getError ( ) const
inline
Returns
Error code if last request was not successful.

◆ getIndexFile()

std::string giri::HTTPSession::getIndexFile ( ) const
inline
Returns
Default index file to be used.

◆ getMimeTypes()

std::map<std::string, std::string> giri::HTTPSession::getMimeTypes ( ) const
inline
Returns
Mapping containing all supported mimetypes.

◆ getRequest()

http::request<http::string_body> giri::HTTPSession::getRequest ( ) const
inline
Returns
HTTP request sent by the client.

◆ getResult()

http::response<http::vector_body<char> > giri::HTTPSession::getResult ( ) const
inline
Returns
Returns default result which the server is about to send back.

◆ getServerString()

std::string giri::HTTPSession::getServerString ( ) const
inline
Returns
Server string to be added to the http answers.

◆ getSSL()

bool giri::HTTPSession::getSSL ( ) const
inline
Returns
true if ssl is enabled, false otherwise.

◆ run()

void giri::HTTPSession::run ( )
inline

Starts receiving messages asynchrolously. Automatically notifies subscribed Observer objects on new messages.

◆ setDocRoot()

void giri::HTTPSession::setDocRoot ( const std::filesystem::path &  path)
inline

Set doc root path. Only affects new requests within this HTTPSession.

Parameters
pathPath to serve html files from.

◆ setIndexFile()

void giri::HTTPSession::setIndexFile ( const std::string &  indx)
inline

Sets default index file to be used. Only affects new requests within this HTTPSession.

Parameters
indxdefault index file to be used.

◆ setResult()

void giri::HTTPSession::setResult ( const http::response< http::vector_body< char >> &  res)
inline

Set custom result to be sent back to the client.

Parameters
resResult to be sent back.

◆ setServerString()

void giri::HTTPSession::setServerString ( const std::string &  servstr)
inline

Set server string to be added to the http answers. Only affects new requests within this HTTPSession.

Parameters
servstrserver string to be added to the http answers.

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