MuHttpServer Class Reference

This class provides a framework for creating HTTP micro servers in Qt. More...

#include <MuHttpServer.h>

Inheritance diagram for MuHttpServer:

Inheritance graph

List of all members.

Public Member Functions

 MuHttpServer (int port=80, QObject *pParent=NULL)
virtual ~MuHttpServer ()
bool start ()
void stop (Subject &subject, const std::string &signal, const boost::any &v)
void registerPath (const QString &path, EHS *pObj)

Protected Slots

void processServer ()
virtual void debug (HttpRequest *pHttpRequest)
virtual void warning (const QString &msg)
void allowNonLocalConnections (bool val)

Protected Member Functions

virtual Response postRequest (const QString &uri, const QString &contentType, const QString &body, const FormValueMap &form)
virtual Response getRequest (const QString &uri, const QString &contentType, const QString &body, const FormValueMap &form)=0

Classes

struct  Response
 This structure contains information used to send a response to an HTTP request. More...


Detailed Description

This class provides a framework for creating HTTP micro servers in Qt.

Definition at line 29 of file MuHttpServer.h.


Constructor & Destructor Documentation

MuHttpServer::MuHttpServer ( int  port = 80,
QObject *  pParent = NULL 
)

Initialize a MuHttpServer object.

Parameters:
port The TCP port that this server will listen. If port is 0, this object is assumed to be a child handler and no network socket will be set up.
pParent The Qt parent of this object.
See also:
registerPath()

virtual MuHttpServer::~MuHttpServer (  )  [virtual]

Clean up the MuHttpServer object and close network sockets.


Member Function Documentation

bool MuHttpServer::start (  ) 

Listen to the network and start processing requests.

Returns:
True if successful or if the server is already running, false if there is an error.

void MuHttpServer::stop ( Subject subject,
const std::string &  signal,
const boost::any &  v 
)

Stop the server.

void MuHttpServer::registerPath ( const QString &  path,
EHS *  pObj 
)

Attach a server path to a response object.

Requests from the registered path will be handled by pObj. For example, registerPath("/test", this) will cause the following requests to be handled by the this object. http://localhost/test/ http://localhost/test/foo http://localhost/test/bar The following will not be handled by the this object. http://localhost/test http://localhost/test/foo/ http://localhost/test/foo/bar http://localhost/foo/

Any paths not explicitly registered will be handled by the root EHS object.

Parameters:
path The path prefix for processing.
pObj The object that wants to processing path.

virtual Response MuHttpServer::postRequest ( const QString &  uri,
const QString &  contentType,
const QString &  body,
const FormValueMap &  form 
) [protected, virtual]

This handles HTTP POST requests.

POST requests encode form data in the request body.

The default behavior is to return an HTTP 403 Forbidden response to the requesting client.

Parameters:
uri The URI of the request. If this object is handling sub requests via registerPath(), this will be a partial URI rooted at the path this object is registered to handle.
contentType The HTTP Content-type of the request.
body The body of the request.
form Form data from the request body.
Returns:
An HTTP Response.

virtual Response MuHttpServer::getRequest ( const QString &  uri,
const QString &  contentType,
const QString &  body,
const FormValueMap &  form 
) [protected, pure virtual]

This handles HTTP GET requests.

GET requests encode form data in the request URL using ? and &.

Parameters:
uri The URI of the request. If this object is handling sub requests via registerPath(), this will be a partial URI rooted at the path this object is registered to handle.
contentType The HTTP Content-type of the request.
body The body of the request. This is usually empty with GET requests.
form Form data encoded in the request URL.
Returns:
An HTTP Response.

Implemented in ImageHandler.

void MuHttpServer::processServer (  )  [protected, slot]

Handle new and existing connections.

This runs one cycle of the server's request loop. The default behavior of a MuHttpServer is to call this slot every 250ms.

virtual void MuHttpServer::debug ( HttpRequest *  pHttpRequest  )  [protected, virtual, slot]

This provides debugging information about an HttpRequest.

The default behavior is to do nothing. If an implementation wants to log all requests for debugging purposes, this method should be overridden.

Parameters:
pHttpRequest The request object.

virtual void MuHttpServer::warning ( const QString &  msg  )  [protected, virtual, slot]

Display a waning message.

The default behavior is to do nothing. If an implementation wants to display extra warning messages, this method should be overridden. This method is called when the underlying HTTP server code throws an error during socket setup, conntection, or processing. It is also called when postRequest() or getRequest() return an HTTPRESPONSECODE_INVALID indicating an internal server error.

Parameters:
msg A user displayable warning message.

void MuHttpServer::allowNonLocalConnections ( bool  val  )  [protected, slot]

Allow connections from machines other than localhost.

The default is to allow only localhost connections.

Parameters:
val If true, any machine can connect. If false, only localhost can connect.

Definition at line 231 of file MuHttpServer.h.


Software Development Kit - Opticks 4.9.0 Build 16218