Files
jellyfin-desktop/external/qhttpserver/examples/helloworld/helloworld.cpp
T

38 lines
787 B
C++
Executable File

#include "helloworld.h"
#include <QCoreApplication>
#include <qhttpserver.h>
#include <qhttprequest.h>
#include <qhttpresponse.h>
/// HelloWorld
HelloWorld::HelloWorld()
{
QHttpServer *server = new QHttpServer(this);
connect(server, SIGNAL(newRequest(QHttpRequest*, QHttpResponse*)),
this, SLOT(handleRequest(QHttpRequest*, QHttpResponse*)));
server->listen(QHostAddress::Any, 8080);
}
void HelloWorld::handleRequest(QHttpRequest *req, QHttpResponse *resp)
{
Q_UNUSED(req);
QByteArray body = "Hello World";
resp->setHeader("Content-Length", QString::number(body.size()));
resp->writeHead(200);
resp->end(body);
}
/// main
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
HelloWorld hello;
app.exec();
}