Hobrasoft httpd server
Embedded HTTP server for Qt and C++
Hobrasoft httpd server

Table of Contents

Author
Petr Bravenec petr..nosp@m.brav.nosp@m.enec@.nosp@m.hobr.nosp@m.asoft.nosp@m..cz

Features

Licence

LGPL

Source code

https://dev.hobrasoft.cz/diffusion/HTTPD/

Usage

Static contents server

Server can be used very easy to server static contents.

#include <QCoreApplication>
#include "httpd.h"
using namespace HobrasoftHttpd;
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
new HttpServer(0); // Server can serve static file from current directory
return app.exec();
}

The configuration of the server can be set in configuration file (Configuration)

#include <QCoreApplication>
#include <QSettings>
#include "httpd.h"
#include "httpsettings.h"
using namespace HobrasoftHttpd;
int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);
QSettings qsettings("/etc/http.conf", QSettings::IniFormat);
HttpSettings settings(&qsettings, 0);
new HttpServer(&settings,0);
return app.exec();
}

Dynamicaly generated pages

If you want to generate your web pages dynamicaly in your application, you have to:

#include "httpserver.h"
#include "myclass.h"
using namespace HobrasoftHttpd;
/*
Extended HttpRequestHandler, default service() method is replace with own implementation
*/
class RequestMapper : public HttpRequestHandler {
Q_OBJECT
public:
RequestMapper(HttpConnection *parent);
void service(HttpRequest *request, HttpResponse *response) {
if (request->path().startsWith("/my-function")) {
HttpRequestHandler controller = new MyClass(connection());
controller->service(request, response);
return;
}
// call default handler - static html pages, shtml pages, images, javascript, styles...
HttpRequestHandler::service(request, response);
}
};
/*
Extended HttpServer, default requestHandler() is replaced with own implementation
*/
class MyHttpd : public HttpServer {
Q_OBJECT
public:
Httpd(QObject *parent) : QObject(parent) { }
// The method returns pointer to new instance of your own request mapper
// The request mapper maps requests like "/my-function" to call your own classes
HttpRequestHandler *requestHandler(HttpConnection *connection) {
return new RequestMapper(connection);
}
};