summaryrefslogtreecommitdiffstats
path: root/tests/auto/httpserver/proxy_server.h
blob: 6be0c4e1ab1b9a0f7473bd1a52a60aaa67f11bc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#ifndef PROXY_SERVER_H
#define PROXY_SERVER_H

#include <QObject>
#include <QTcpServer>

class ProxyServer : public QObject
{
    Q_OBJECT

public:
    explicit ProxyServer(QObject *parent = nullptr);
    void setCredentials(const QByteArray &user, const QByteArray password);
    void setCookie(const QByteArray &cookie);
    bool isListening();
    void setPort(int port);

public slots:
    void run();

private slots:
    void handleNewConnection();
    void handleReadReady();

signals:
    void authenticationSuccess();
    void cookieMatch();
    void requestReceived();

private:
    int m_port = 5555;
    QByteArray m_data;
    QTcpServer m_server;
    QByteArray m_auth;
    QByteArray m_cookie;
    bool m_authenticate = false;
};

#endif // PROXY_SERVER_H