join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
join::BasicHttpWorker< Protocol > Class Template Reference

basic HTTP worker. More...

#include <httpserver.hpp>

Inheritance diagram for join::BasicHttpWorker< Protocol >:
Collaboration diagram for join::BasicHttpWorker< Protocol >:

Public Types

using Content = BasicHttpContent <Protocol>
 
using Server = BasicHttpServer <Protocol>
 

Public Member Functions

 BasicHttpWorker (Server *server)
 create the worker instance.
 
 BasicHttpWorker (const BasicHttpWorker &other)=delete
 create instance by copy.
 
BasicHttpWorkeroperator= (const BasicHttpWorker &other)=delete
 assign instance by copy.
 
 BasicHttpWorker (BasicHttpWorker &&other)=delete
 create instance by move.
 
BasicHttpWorkeroperator= (BasicHttpWorker &&other)=delete
 assign instance by move.
 
virtual ~BasicHttpWorker ()
 destroy worker thread.
 
void sendHeaders ()
 send headers.
 
void sendError (const std::string &status, const std::string &reason)
 send error message.
 
void sendRedirect (const std::string &status, const std::string &reason, const std::string &location={})
 send redirect message.
 
void sendFile (const std::string &path)
 send a file.
 
bool hasHeader (const std::string &name) const
 checks if there is a HTTP request header with the specified name.
 
std::string header (const std::string &name) const
 get HTTP request header by name.
 
size_t contentLength () const
 get content length.
 
void header (const std::string &name, const std::string &val)
 add header to the HTTP response.
 

Protected Member Functions

void work ()
 worker thread routine.
 
void processRequest ()
 process the HTTP request.
 
int readRequest ()
 read the HTTP request.
 
void writeResponse ()
 write the HTTP response.
 
void cleanUp ()
 clean all.
 
void endRequest ()
 end the HTTP request.
 
void setEncoding (const std::vector< std::string > &encodings)
 set stream encoding.
 
void clearEncoding ()
 clear stream encoding.
 

Protected Attributes

int _max = 0
 max requests.
 
HttpRequest _request
 HTTP request.
 
HttpResponse _response
 HTTP response.
 
std::streambuf * _streambuf = nullptr
 HTTP stream buffer.
 
bool _wrapped = false
 HTTP stream status.
 
Server_server
 HTTP server.
 
Thread _thread
 thread.
 

Detailed Description

template<class Protocol>
class join::BasicHttpWorker< Protocol >

basic HTTP worker.

Member Typedef Documentation

◆ Content

template<class Protocol >
using join::BasicHttpWorker< Protocol >::Content = BasicHttpContent <Protocol>

◆ Server

template<class Protocol >
using join::BasicHttpWorker< Protocol >::Server = BasicHttpServer <Protocol>

Constructor & Destructor Documentation

◆ BasicHttpWorker() [1/3]

template<class Protocol >
join::BasicHttpWorker< Protocol >::BasicHttpWorker ( Server * server)
inline

create the worker instance.

Parameters
serverServer instance.

◆ BasicHttpWorker() [2/3]

template<class Protocol >
join::BasicHttpWorker< Protocol >::BasicHttpWorker ( const BasicHttpWorker< Protocol > & other)
delete

create instance by copy.

Parameters
otherobject to copy.

◆ BasicHttpWorker() [3/3]

template<class Protocol >
join::BasicHttpWorker< Protocol >::BasicHttpWorker ( BasicHttpWorker< Protocol > && other)
delete

create instance by move.

Parameters
otherobject to move.

◆ ~BasicHttpWorker()

template<class Protocol >
virtual join::BasicHttpWorker< Protocol >::~BasicHttpWorker ( )
inlinevirtual

destroy worker thread.

Member Function Documentation

◆ cleanUp()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::cleanUp ( )
inlineprotected

clean all.

◆ clearEncoding()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::clearEncoding ( )
inlineprotected

clear stream encoding.

◆ contentLength()

template<class Protocol >
size_t join::BasicHttpWorker< Protocol >::contentLength ( ) const
inline

get content length.

Returns
content length.

◆ endRequest()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::endRequest ( )
inlineprotected

end the HTTP request.

◆ hasHeader()

template<class Protocol >
bool join::BasicHttpWorker< Protocol >::hasHeader ( const std::string & name) const
inline

checks if there is a HTTP request header with the specified name.

Parameters
namename of the HTTP request header to search for.
Returns
true of there is such a HTTP request header, false otherwise.

◆ header() [1/2]

template<class Protocol >
std::string join::BasicHttpWorker< Protocol >::header ( const std::string & name) const
inline

get HTTP request header by name.

Parameters
nameheader name.
Returns
header value.

◆ header() [2/2]

template<class Protocol >
void join::BasicHttpWorker< Protocol >::header ( const std::string & name,
const std::string & val )
inline

add header to the HTTP response.

Parameters
nameheader name.
valheader value.

◆ operator=() [1/2]

template<class Protocol >
BasicHttpWorker & join::BasicHttpWorker< Protocol >::operator= ( BasicHttpWorker< Protocol > && other)
delete

assign instance by move.

Parameters
otherobject to move.
Returns
a reference of the current object.

◆ operator=() [2/2]

template<class Protocol >
BasicHttpWorker & join::BasicHttpWorker< Protocol >::operator= ( const BasicHttpWorker< Protocol > & other)
delete

assign instance by copy.

Parameters
otherobject to copy.
Returns
a reference of the current object.

◆ processRequest()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::processRequest ( )
inlineprotected

process the HTTP request.

◆ readRequest()

template<class Protocol >
int join::BasicHttpWorker< Protocol >::readRequest ( )
inlineprotected

read the HTTP request.

Returns
0 on success, -1 on failure.

◆ sendError()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::sendError ( const std::string & status,
const std::string & reason )
inline

send error message.

Parameters
statusstatus.
reasonreason.

◆ sendFile()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::sendFile ( const std::string & path)
inline

send a file.

Parameters
pathpath of the file.

◆ sendHeaders()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::sendHeaders ( )
inline

send headers.

◆ sendRedirect()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::sendRedirect ( const std::string & status,
const std::string & reason,
const std::string & location = {} )
inline

send redirect message.

Parameters
statusstatus.
reasonreason.
locationlocation to redirect to.

◆ setEncoding()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::setEncoding ( const std::vector< std::string > & encodings)
inlineprotected

set stream encoding.

Parameters
encodingsencodings applied to the stream.

◆ work()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::work ( )
inlineprotected

worker thread routine.

◆ writeResponse()

template<class Protocol >
void join::BasicHttpWorker< Protocol >::writeResponse ( )
inlineprotected

write the HTTP response.

Member Data Documentation

◆ _max

template<class Protocol >
int join::BasicHttpWorker< Protocol >::_max = 0
protected

max requests.

◆ _request

template<class Protocol >
HttpRequest join::BasicHttpWorker< Protocol >::_request
protected

HTTP request.

◆ _response

template<class Protocol >
HttpResponse join::BasicHttpWorker< Protocol >::_response
protected

HTTP response.

◆ _server

template<class Protocol >
Server* join::BasicHttpWorker< Protocol >::_server
protected

HTTP server.

◆ _streambuf

template<class Protocol >
std::streambuf* join::BasicHttpWorker< Protocol >::_streambuf = nullptr
protected

HTTP stream buffer.

◆ _thread

template<class Protocol >
Thread join::BasicHttpWorker< Protocol >::_thread
protected

thread.

◆ _wrapped

template<class Protocol >
bool join::BasicHttpWorker< Protocol >::_wrapped = false
protected

HTTP stream status.


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