Skip to content

HTTP Connection Is Being Established But Handler Never Triggers Process() Please Help! #39

@omidnabi

Description

@omidnabi

Hi guys, I'm having a very weird problem, with the server I'm trying to setup. Everything seems to go well as far connecting to the server, but for some reason process() never gets triggered. Note I use server.setHandler() in my api to assign an instantiaton of the class below. Then I call server.listen(). Please see the code below:

`#ifndef HTTP_HANDLER_H
#define HTTP_HANDLER_H

#include
#include <qhttpengine/handler.h>

class HttpHandler : public QHttpEngine::Handler
{
Q_OBJECT

public:
HttpHandler(QObject* parent = nullptr);
virtual ~HttpHandler();

signals:
void messageReceived(QHttpEngine::Socket* socket, const QString& path);

protected:
void process(QHttpEngine::Socket *socket, const QString &path) override;
};

#endif
`

`#include "HttpHandler.h"
#include <qhttpengine/socket.h>

HttpHandler::HttpHandler(QObject *parent) : QHttpEngine::Handler(parent)
{
}

HttpHandler::~HttpHandler()
{

}

void HttpHandler::process(QHttpEngine::Socket *socket, const QString &path)
{
qDebug() << "HTTP request received! Path:" << path;

// Read the raw request data as a QByteArray
QByteArray requestData = socket->readAll();

// Process the raw data as needed
qDebug() << "Raw Request Data:" << requestData;

// You can now parse and handle the requestData
// For example, you can parse it as JSON if it's in JSON format:
// QJsonDocument jsonDocument = QJsonDocument::fromJson(requestData);
// QJsonObject jsonObject = jsonDocument.object();
// ... (perform further processing)

// Respond to the request (for example, with a simple OK response)
socket->setStatusCode(QHttpEngine::Socket::OK);
socket->writeHeaders();
socket->close();
emit messageReceived(socket, path);

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions