#include <MuHttpServer.h>

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... | |
Definition at line 29 of file MuHttpServer.h.
| MuHttpServer::MuHttpServer | ( | int | port = 80, |
|
| QObject * | pParent = NULL | |||
| ) |
Initialize a MuHttpServer object.
| 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. |
| virtual MuHttpServer::~MuHttpServer | ( | ) | [virtual] |
Clean up the MuHttpServer object and close network sockets.
| bool MuHttpServer::start | ( | ) |
Listen to the network and start processing requests.
| 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.
| 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.
| 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. |
| 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 &.
| 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. |
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.
| 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.
| 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.
| val | If true, any machine can connect. If false, only localhost can connect. |
Definition at line 231 of file MuHttpServer.h.