Git Product home page Git Product logo

qhttpserver's Introduction

QHttpServer

A Qt HTTP Server - because hard-core programmers write web-apps in C++ :)

It uses Ryan Dahl's HTTP Parser and is asynchronous and does not require any inheritance.

QHttpServer is available under the MIT License.

NOTE: QHttpServer is NOT fully HTTP compliant right now! DO NOT use it for anything complex

Installation

Requires Qt 4 or Qt 5.

qmake && make && su -c 'make install'

To link to your projects put this in your project's qmake project file

LIBS += -lqhttpserver

By default, the installation prefix is /usr/local. To change that to /usr, for example, run:

qmake -r PREFIX=/usr

Usage

Include the headers

#include <qhttpserver.h>
#include <qhttprequest.h>
#include <qhttpresponse.h>

Create a server, and connect to the signal for new requests

QHttpServer *server = new QHttpServer;
connect(server, SIGNAL(newRequest(QHttpRequest*, QHttpResponse*)),
        handler, SLOT(handle(QHttpRequest*, QHttpResponse*)));

// let's go
server->listen(8080);

In the handler, you may dispatch on routes or do whatever other things you want. See the API documentation for what information is provided about the request via the QHttpRequest object.

To send data back to the browser and end the request:

void Handler::handle(QHttpRequest *req, QHttpResponse *resp)
{
	resp->setHeader("Content-Length", 11);
	resp->writeHead(200); // everything is OK
	resp->write("Hello World");
	resp->end();
}

The server and request/response objects emit various signals and have guarantees about memory management. See the API documentation for these.

Contribute

Feel free to file issues, branch and send pull requests. If you plan to work on a major feature (say WebSocket support), please run it by me first by filing an issue! qhttpserver has a narrow scope and API and I'd like to keep it that way, so a thousand line patch that implements the kitchen sink is unlikely to be accepted.

  • Nikhil Marathe (maintainer)

Everybody who has ever contributed shows up in Contributors.

qhttpserver's People

Contributors

carbn avatar christian-sahlmann avatar davidiw avatar mxnemu avatar nikhilm avatar viking avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.