Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::remote::HttpServer Class Reference

#include "httpserver.h"

Inheritance diagram for ion::remote::HttpServer:

Classes

class  RequestHandler
 RequestHandlers handle requests for a file or path. More...
 
class  Websocket
 Represents the server side of a connected Websocket. More...
 

Public Types

typedef std::map< std::string,
std::string > 
QueryMap
 
typedef std::map< void
*, WebsocketHelper * > 
WebsocketMap
 
typedef base::ReferentPtr
< Websocket >::Type 
WebsocketPtr
 
typedef base::ReferentPtr
< RequestHandler >::Type 
RequestHandlerPtr
 
typedef std::map< std::string,
RequestHandlerPtr
HandlerMap
 

Public Member Functions

 HttpServer (int port, int num_threads)
 Starts a HttpServer on the passed port with the passed number of handler threads. More...
 
virtual ~HttpServer ()
 
const std::string GetUriData (const std::string &uri) const
 Returns the data of the requested URI, or returns an empty string if it does not exist. More...
 
bool IsRunning () const
 Returns whether the server is running. More...
 
void RegisterHandler (const RequestHandlerPtr &handler)
 Registers the passed handler at the path returned by handler->GetBasePath(). More...
 
void UnregisterHandler (const std::string &path)
 Unregisters the handler at path. More...
 
HandlerMap GetHandlers () const
 Returns the handlers registered with this server. More...
 
bool EmbedLocalSourcedFiles () const
 Gets, sets whether local sourced files (tags with src=... More...
 
void SetEmbedLocalSourcedFiles (bool embed)
 
size_t WebsocketCount ()
 Return the number of currently-connected websockets. More...
 
const std::string & GetFooterHtml () const
 Sets/gets the header and footer HTML, which are both empty by default. More...
 
const std::string & GetHeaderHtml () const
 
void SetFooterHtml (const std::string &str)
 
void SetHeaderHtml (const std::string &str)
 

Friends

class WebsocketHelper
 These methods and fields are all concerned with keeping track of active websocket connections. More...
 

Detailed Description

Definition at line 33 of file httpserver.h.

Member Typedef Documentation

Definition at line 116 of file httpserver.h.

typedef std::map<std::string, std::string> ion::remote::HttpServer::QueryMap

Definition at line 35 of file httpserver.h.

Definition at line 38 of file httpserver.h.

Constructor & Destructor Documentation

ion::remote::HttpServer::HttpServer ( int  port,
int  num_threads 
)

Starts a HttpServer on the passed port with the passed number of handler threads.

Passing a negative port is an error, but passing port 0 will be silently ignored (the server will not be reachable over a network interface but there will be no reported startup errors).

Definition at line 659 of file httpserver.cc.

ion::remote::HttpServer::~HttpServer ( )
virtual

Definition at line 688 of file httpserver.cc.

Member Function Documentation

bool ion::remote::HttpServer::EmbedLocalSourcedFiles ( ) const
inline

Gets, sets whether local sourced files (tags with src=...

such as img and script that reference files starting with '/') should be embedded in returned HTML pages.

Definition at line 144 of file httpserver.h.

const std::string& ion::remote::HttpServer::GetFooterHtml ( ) const
inline

Sets/gets the header and footer HTML, which are both empty by default.

When RequestHandlers return HTML pages, the special string is replaced by the header HTML, while is replaced by the footer HTML.

Definition at line 156 of file httpserver.h.

HttpServer::HandlerMap ion::remote::HttpServer::GetHandlers ( ) const

Returns the handlers registered with this server.

Definition at line 729 of file httpserver.cc.

Referenced by ion::remote::RemoteServer::AddNode(), GetUriData(), and ion::remote::RemoteServer::RemoveNode().

const std::string& ion::remote::HttpServer::GetHeaderHtml ( ) const
inline

Definition at line 157 of file httpserver.h.

const std::string ion::remote::HttpServer::GetUriData ( const std::string &  uri) const

Returns the data of the requested URI, or returns an empty string if it does not exist.

Definition at line 695 of file httpserver.cc.

References GetHandlers(), and ion::base::StartsWith().

bool ion::remote::HttpServer::IsRunning ( ) const

Returns whether the server is running.

Definition at line 710 of file httpserver.cc.

void ion::remote::HttpServer::RegisterHandler ( const RequestHandlerPtr handler)

Registers the passed handler at the path returned by handler->GetBasePath().

Definition at line 714 of file httpserver.cc.

References DCHECK, ion::base::SharedPtr< T >::Get(), and ion::base::RemoveSuffix().

Referenced by ion::remote::RemoteServer::RemoteServer().

void ion::remote::HttpServer::SetEmbedLocalSourcedFiles ( bool  embed)
inline

Definition at line 145 of file httpserver.h.

void ion::remote::HttpServer::SetFooterHtml ( const std::string &  str)
inline

Definition at line 158 of file httpserver.h.

References str.

void ion::remote::HttpServer::SetHeaderHtml ( const std::string &  str)
inline

Definition at line 159 of file httpserver.h.

References str.

void ion::remote::HttpServer::UnregisterHandler ( const std::string &  path)

Unregisters the handler at path.

Definition at line 724 of file httpserver.cc.

size_t ion::remote::HttpServer::WebsocketCount ( )

Return the number of currently-connected websockets.

Definition at line 765 of file httpserver.cc.

Friends And Related Function Documentation

friend class WebsocketHelper
friend

These methods and fields are all concerned with keeping track of active websocket connections.

None of this would be necessary if Mongoose's mg_connection held a per-connection user_data void* that could be used to directly access the websocket handler.

Definition at line 166 of file httpserver.h.


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