Single instance HTTP Server using WiFly Interface.

Dependents:   WiFlyHTTPServerSample MultiThreadingHTTPServer

Embed: (wiki syntax)

« Back to documentation index

HttpServer Class Reference

This is the non-blocking HTTP Server class. More...

#include <HttpServer.h>

Data Structures

struct  handlersComp
 Structure which will allow to order the stored handlers according to their associated path. More...

Public Member Functions

void HandleRequest (HTTPConnection::HTTPMessage *msg)
 Internal function which processes a request and which will try to find the matching handler function for the given request.
template<typename T >
void addHandler (const char *path)
 Adds a request handler to the handlers list.
void addErrorHandler (HTTPRequestHandlerFunction hdlFunc)
 Replaces the standard error Handler.

Static Public Member Functions

static void StdErrorHandler (HTTPConnection::HTTPMessage &msg)
 The standard error handler function.

Static Public Attributes

static map< string,
HTTPRequestHandler *(*)(const
char *, const char
*, HTTPConnection::HTTPMessage
&), handlersComp
m_lpHandlers
 Map of handler objects.

Detailed Description

This is the non-blocking HTTP Server class.

The idea behind this class is as follows: the user may instantiate the class and initialize it. Once the server is setup and listening, the server will stay in an endless loop and keep on listening for new connections and for new HTTP requests. Once a request is received it will be placed in a queue. The queue itself will be handled in a separate task.

Definition at line 41 of file HttpServer.h.


Member Function Documentation

void addErrorHandler ( HTTPRequestHandlerFunction  hdlFunc )

Replaces the standard error Handler.

The error Handler will be called everytime a request is not matching any of the registered paths or uris.

Parameters:
hdlFunc,:User specified handler function which will be used in error conditions.

Definition at line 117 of file HttpServer.h.

void addHandler ( const char *  path )

Adds a request handler to the handlers list.

You will have to use one of the existing implementations. With each handler a uri or path is associated. Whenever a request is received the server will walk through all registered handlers and check which path is matching.

Parameters:
T: class which will be instanciated to serve these requests for the associated path.
path: request uri starting with this path will be served using this handler.

Definition at line 109 of file HttpServer.h.

void HandleRequest ( HTTPConnection::HTTPMessage msg )

Internal function which processes a request and which will try to find the matching handler function for the given request.

Please note that the function will search through the list of handlers, iterating from longest to shortest paths. If the registered path is a subset of the request the associated handler is considered as being a match.

Parameters:
msg: Request message data. Contains the requested logical uri.
tcp: Socket to be used for communication with the client.

Definition at line 444 of file HttpServer.cpp.

void StdErrorHandler ( HTTPConnection::HTTPMessage msg ) [static]

The standard error handler function.

Parameters:
msg: Request message data.
tcp: Socket to be used for responding.

Definition at line 435 of file HttpServer.cpp.


Field Documentation

map< string, HTTPRequestHandler *(*)(const char *, const char *, HTTPConnection::HTTPMessage &), HttpServer::handlersComp > m_lpHandlers [static]

Map of handler objects.

Can be any object derived from HTTPRequestHeader. Use the addHandler function to register new handler objects.

Definition at line 99 of file HttpServer.h.