Nebula
Loading...
Searching...
No Matches
Http::HttpServer Class Reference

#include <httpserver.h>

Detailed Description

Implements an extremly simple standalone HTTP server with attached HttpRequestHandlers.

Can be used to serve debug information about the Nebula application to web browsers.

Inherits Core::RefCounted.

Classes

struct  PendingRequest
 

Public Member Functions

 HttpServer ()
 constructor
 
virtual ~HttpServer ()
 destructor
 
void SetPort (ushort p)
 set port number for http service
 
ushort GetPort () const
 get port number of http service
 
void SetSingleThreadMode (bool b)
 turn single-thread mode on/off (useful for debugging), default is off
 
bool IsSingleThreadMode () const
 get single-thread mode
 
bool Open ()
 open the http server
 
void Close ()
 close the http server
 
bool IsOpen () const
 return true if server is open
 
void AttachRequestHandler (const Ptr< HttpRequestHandler > &h)
 attach a request handler to the server
 
void RemoveRequestHandler (const Ptr< HttpRequestHandler > &h)
 remove a request handler from the server
 
Util::Array< Ptr< HttpRequestHandler > > GetRequestHandlers () const
 get registered request handlers
 
void OnFrame ()
 call this method frequently to serve http connections
 
- Public Member Functions inherited from Core::RefCounted
 RefCounted ()
 constructor
 
int GetRefCount () const
 get the current refcount
 
void AddRef ()
 increment refcount by one
 
void Release ()
 decrement refcount and destroy object if refcount is zero
 
bool IsInstanceOf (const Rtti &rtti) const
 return true if this object is instance of given class
 
bool IsInstanceOf (const Util::String &className) const
 return true if this object is instance of given class by string
 
bool IsInstanceOf (const Util::FourCC &classFourCC) const
 return true if this object is instance of given class by fourcc
 
bool IsA (const Rtti &rtti) const
 return true if this object is instance of given class, or a derived class
 
bool IsA (const Util::String &rttiName) const
 return true if this object is instance of given class, or a derived class, by string
 
bool IsA (const Util::FourCC &rttiFourCC) const
 return true if this object is instance of given class, or a derived class, by fourcc
 
const Util::StringGetClassName () const
 get the class name
 
Util::FourCC GetClassFourCC () const
 get the class FourCC code
 

Private Member Functions

 __DeclareClass (HttpServer)
 
 __DeclareSingleton (HttpServer)
 
bool HandleHttpRequest (const Ptr< Net::TcpClientConnection > &clientConnection)
 handle an HttpRequest
 
bool BuildHttpResponse (const Ptr< Net::TcpClientConnection > &clientConnection, const Ptr< HttpRequest > &httpRequest)
 build an HttpResponse for a handled http request
 

Private Attributes

Util::Dictionary< Util::String, Ptr< HttpRequestHandler > > requestHandlers
 
Ptr< DefaultHttpRequestHandlerdefaultRequestHandler
 
Net::IpAddress ipAddress
 
Ptr< Net::TcpServertcpServer
 
Util::Array< PendingRequestpendingRequests
 
bool isOpen
 
bool isSingleThreadMode
 

Additional Inherited Members

- Static Public Member Functions inherited from Core::RefCounted
static void DumpRefCountingLeaks ()
 dump refcounting leaks, call at end of application (NEBULA_DEBUG builds only!)
 
- Protected Member Functions inherited from Core::RefCounted
virtual ~RefCounted ()
 destructor (called when refcount reaches zero)
 

Constructor & Destructor Documentation

◆ HttpServer()

Http::HttpServer::HttpServer ( )

constructor

◆ ~HttpServer()

Http::HttpServer::~HttpServer ( )
virtual

destructor

Member Function Documentation

◆ __DeclareClass()

Http::HttpServer::__DeclareClass ( HttpServer )
private

◆ __DeclareSingleton()

Http::HttpServer::__DeclareSingleton ( HttpServer )
private

◆ AttachRequestHandler()

void Http::HttpServer::AttachRequestHandler ( const Ptr< HttpRequestHandler > & h)

attach a request handler to the server

◆ BuildHttpResponse()

bool Http::HttpServer::BuildHttpResponse ( const Ptr< Net::TcpClientConnection > & clientConnection,
const Ptr< HttpRequest > & httpRequest )
private

build an HttpResponse for a handled http request

◆ Close()

void Http::HttpServer::Close ( )

close the http server

◆ GetPort()

ushort Http::HttpServer::GetPort ( ) const
inline

get port number of http service

◆ GetRequestHandlers()

Util::Array< Ptr< HttpRequestHandler > > Http::HttpServer::GetRequestHandlers ( ) const
inline

get registered request handlers

◆ HandleHttpRequest()

bool Http::HttpServer::HandleHttpRequest ( const Ptr< Net::TcpClientConnection > & clientConnection)
private

handle an HttpRequest

◆ IsOpen()

bool Http::HttpServer::IsOpen ( ) const
inline

return true if server is open

◆ IsSingleThreadMode()

bool Http::HttpServer::IsSingleThreadMode ( ) const
inline

get single-thread mode

◆ OnFrame()

void Http::HttpServer::OnFrame ( )

call this method frequently to serve http connections

◆ Open()

bool Http::HttpServer::Open ( )

open the http server

◆ RemoveRequestHandler()

void Http::HttpServer::RemoveRequestHandler ( const Ptr< HttpRequestHandler > & h)

remove a request handler from the server

◆ SetPort()

void Http::HttpServer::SetPort ( ushort p)
inline

set port number for http service

◆ SetSingleThreadMode()

void Http::HttpServer::SetSingleThreadMode ( bool b)
inline

turn single-thread mode on/off (useful for debugging), default is off

Switch on single thread mode, default is off.

In single thread mode, http requests will be processed immediately in the OnFrame() method, not added to the request handler for asynchronous processing. This may be useful for debugging, but is dangerous/impossible if HTTP request handlers live in different threads!!!

Member Data Documentation

◆ defaultRequestHandler

Ptr<DefaultHttpRequestHandler> Http::HttpServer::defaultRequestHandler
private

◆ ipAddress

Net::IpAddress Http::HttpServer::ipAddress
private

◆ isOpen

bool Http::HttpServer::isOpen
private

◆ isSingleThreadMode

bool Http::HttpServer::isSingleThreadMode
private

◆ pendingRequests

Util::Array<PendingRequest> Http::HttpServer::pendingRequests
private

◆ requestHandlers

Util::Dictionary<Util::String, Ptr<HttpRequestHandler> > Http::HttpServer::requestHandlers
private

◆ tcpServer

Ptr<Net::TcpServer> Http::HttpServer::tcpServer
private

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