-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhttp.h
More file actions
63 lines (39 loc) · 1.31 KB
/
Copy pathhttp.h
File metadata and controls
63 lines (39 loc) · 1.31 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef HTTP_H
#define HTTP_H
#define HTTP_REQUEST_TIMEOUT 5000
#include <QSettings>
#include <QTcpServer>
#include <QTcpSocket>
class Request
{
public:
Request(QTcpSocket *socket) : m_socket(socket) {}
inline QTcpSocket *socket(void) { return m_socket; }
inline QString method(void) { return m_method; }
inline void setMethod(const QString &value) { m_method = value; }
inline QString url(void) { return m_url; }
inline void setUrl(const QString &value) { m_url = value; }
inline QString body(void) { return m_body; }
inline void setBody(const QString &value) { m_body = value; }
inline QMap <QString, QString> &headers(void) { return m_headers; }
inline QMap <QString, QString> &data(void) { return m_data; }
private:
QTcpSocket *m_socket;
QString m_method, m_url, m_body;
QMap <QString, QString> m_headers, m_data;
};
class HTTP : public QObject
{
Q_OBJECT
public:
HTTP(QSettings *settings, QObject *parent = nullptr);
void sendResponse(Request &request, quint16 code, const QMap <QString, QString> &headers = QMap <QString, QString> (), const QByteArray &response = QByteArray());
private:
QTcpServer *m_server;
private slots:
void newConnection(void);
void readyRead(void);
signals:
void requestReceived(Request &request);
};
#endif