acossette / pillow

Small, light and fluffy Qt Http Server
78 stars 26 forks source link

Pillow - A small, light and fluffy web server.

Pillow is a small http server library built with Qt. It is meant to be embedded in Qt apps, where it can assist in exposing an http interface to the app, or to be used as the basis for implementing a small web server app using Qt and/or QtScript.

Pillow is

Pillow is not

Pillow is not a web application framework. Pillow does not provide a full framework to develop web applications; it only deals with receiving client requests, handling them to you and sending back your response. Whether you develop a C++ or QtScript/Javascript app framework, or integrate Ruby and a Rack interface to run Rails app on top of it is up to you. The Pillow core does not go there.

Pillow is not meant to be used in a hostile environment (such as a public server). While it contains a few basic mecanism to defend itself against malicious request, I did not develop Pillow with security as my main concern. Pillow requires the Qt event loop, which while not specifically optimized for networking code, allows for using all of Qt's asynchronous classes.

Examples

A simple file server:

HttpServer* server = new HttpServer(QHostAddress::Any, 4567);
HttpHandlerFile* handler = new HttpHandlerFile("/some/public/path");
connect(server, SIGNAL(requestReady(Pillow::HttpRequest*)),
        handler, SLOT(handleRequest(Pillow::HttpRequest*)));

A simple QtScript/Javascript web application:

HttpServer* server = new HttpServer(QHostAddress(QHostAddress::Any), 4567); 
QScriptEngine* scriptEngine = new QScriptEngine(server);
HttpHandlerStack* handler = new HttpHandlerStack(server);
    new HttpHandlerLog(handler);
    new HttpHandlerQtScriptFile(scriptEngine, "test.js", "handleRequest", true, handler);
    new HttpHandler404(handler);
connect(server, SIGNAL(requestReady(Pillow::HttpRequest*)),
        handler, SLOT(handleRequest(Pillow::HttpRequest*)));

Building

Tested with: Qt 4.8 and Qt 5.5

Tested on the following OS/Compiler/Qt combinations:

Dependencies: At lest the following Qt development modules: QtCore, QtNetwork (with SSL support enabled) and QtScript. I have plans to make the QtNetwork SSL and QtScript dependencies optional. However, they should be included out of the box in the Qt dev packages of most Linux distros, and they are included in the official Qt packages for Windows.

From a shell or command line prompt:

Build:

cd /path/to/pillow
qmake   # Or the full path to Qt's qmake
make    # Or nmake, if you are building with MSVC.
# ... Wait a few seconds
# The pillowcore lib has been placed in the "lib" folder and the various examples
# have been also compiled in their own folder.

Test:

cd tests
./tests # Or ./release/tests.exe on Windows
# If all tests pass, you are good to go. If some fails, please post a bug or help fix it!
# Note that some tests are especially flaky on Windows.

Integrate:

License

Ruby License, http://www.ruby-lang.org/en/LICENSE.txt.

Credits