diff --git a/examples/auth/client.cpp b/examples/auth/client.cpp index 16182be..fc97997 100644 --- a/examples/auth/client.cpp +++ b/examples/auth/client.cpp @@ -21,6 +21,8 @@ */ #include +#include +#include #include #include #include @@ -28,15 +30,13 @@ #include #include -#include - int main(int argc, char * argv[]) { QCoreApplication a(argc, argv); // Attempt to open the local file and read from it - QHttpEngine::LocalFile file; - if (!file.open()) { + QFile file(QDir::home().absoluteFilePath(".authserver")); + if (!file.open(QIODevice::ReadOnly)) { qCritical("Unable to open local file - is server running?"); return 1; } @@ -48,6 +48,9 @@ int main(int argc, char * argv[]) return 1; } + // Close the file + file.close(); + // Create a request to the server, using the provided port and passing the // auth token as a custom HTTP header QUrl url(QString("http://127.0.0.1:%1/").arg(obj.value("port").toInt())); diff --git a/examples/auth/server.cpp b/examples/auth/server.cpp index f280244..269ed3b 100644 --- a/examples/auth/server.cpp +++ b/examples/auth/server.cpp @@ -28,12 +28,19 @@ #include #include #include +#include int main(int argc, char * argv[]) { QCoreApplication a(argc, argv); QHttpEngine::QObjectHandler handler; + handler.registerMethod("", [](QHttpEngine::Socket *socket) { + socket->setStatusCode(QHttpEngine::Socket::OK); + socket->writeHeaders(); + socket->close(); + }); + QHttpEngine::Server server(&handler); if (!server.listen(QHostAddress::LocalHost)) { qCritical("unable to bind to a local port");