Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
testhttpserver_p.h
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4
#
ifndef
TESTHTTPSERVER_P_H
5
#
define
TESTHTTPSERVER_P_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QTcpServer
>
19
#
include
<
QUrl
>
20
#
include
<
QThread
>
21
#
include
<
QMutex
>
22
#
include
<
QWaitCondition
>
23
#
include
<
private
/
qglobal_p
.
h
>
24
#
include
<
QObject
>
25
#
include
<
QSet
>
26
#
include
<
QList
>
27
#
include
<
QString
>
28
#
include
<
utility
>
29
30
QT_BEGIN_NAMESPACE
31
32
class
TestHTTPServer :
public
QObject
33
{
34
Q_OBJECT
35
public
:
36
TestHTTPServer();
37
38
bool
listen();
39
quint16 port()
const
;
40
QUrl baseUrl()
const
;
41
QUrl url(
const
QString &documentPath)
const
;
42
QString urlString(
const
QString &documentPath)
const
;
43
QString errorString()
const
;
44
45
enum
Mode { Normal, Delay, Disconnect };
46
bool
serveDirectory(
const
QString &, Mode = Normal);
47
48
bool
wait(
const
QUrl &expect,
const
QUrl &reply,
const
QUrl &body);
49
bool
hasFailed()
const
;
50
51
void
addAlias(
const
QString &filename,
const
QString &aliasName);
52
void
addRedirect(
const
QString &filename,
const
QString &redirectName);
53
54
void
registerFileNameForContentSubstitution(
const
QString &fileName);
55
56
// In Delay mode, each item needs one call to this function to be sent
57
void
sendDelayedItem();
58
59
qsizetype chunkSize()
const
{
return
m_chunkSize; }
60
void
setChunkSize(qsizetype chunkSize) { m_chunkSize = chunkSize; }
61
62
private
Q_SLOTS:
63
void
newConnection();
64
void
disconnected();
65
void
readyRead();
66
void
sendOne();
67
void
sendChunk();
68
69
private
:
70
enum
State {
71
AwaitingHeader,
72
AwaitingData,
73
Failed
74
};
75
76
void
serveGET(QTcpSocket *,
const
QByteArray &);
77
bool
reply(QTcpSocket *,
const
QByteArray &);
78
79
QList<std::pair<QString, Mode> > m_directories;
80
QHash<QTcpSocket *, QByteArray> m_dataCache;
81
QList<std::pair<QTcpSocket *, QByteArray> > m_toSend;
82
QSet<QString> m_contentSubstitutedFileNames;
83
84
struct
WaitData {
85
QList<QByteArray> headerExactMatches;
86
QList<QByteArray> headerPrefixes;
87
QByteArray body;
88
} m_waitData;
89
QByteArray m_replyData;
90
QByteArray m_bodyData;
91
QByteArray m_data;
92
State m_state;
93
94
QHash<QString, QString> m_aliases;
95
QHash<QString, QString> m_redirects;
96
97
QTcpServer m_server;
98
99
qsizetype m_chunkSize = std::numeric_limits<qsizetype>::max();
100
};
101
102
class
ThreadedTestHTTPServer
:
public
QThread
103
{
104
Q_OBJECT
105
public
:
106
ThreadedTestHTTPServer
(
const
QString
&
dir
,
TestHTTPServer
::
Mode
mode
=
TestHTTPServer
::
Normal
);
107
ThreadedTestHTTPServer
(
const
QHash<QString, TestHTTPServer::Mode> &dirs);
108
~
ThreadedTestHTTPServer
();
109
110
QUrl
baseUrl
()
const
;
111
QUrl
url
(
const
QString &documentPath)
const
;
112
QString
urlString
(
const
QString &documentPath)
const
;
113
114
protected
:
115
void
run
()
override
;
116
117
private
:
118
void
start();
119
120
QHash<QString, TestHTTPServer::Mode> m_dirs;
121
quint16 m_port;
122
QMutex m_mutex;
123
QWaitCondition m_condition;
124
};
125
126
QT_END_NAMESPACE
127
128
#
endif
// TESTHTTPSERVER_P_H
ThreadedTestHTTPServer
Definition
testhttpserver_p.h:103
ThreadedTestHTTPServer::run
void run() override
Definition
testhttpserver.cpp:443
ThreadedTestHTTPServer::urlString
QString urlString(const QString &documentPath) const
Definition
testhttpserver.cpp:438
ThreadedTestHTTPServer::ThreadedTestHTTPServer
ThreadedTestHTTPServer(const QHash< QString, TestHTTPServer::Mode > &dirs)
Definition
testhttpserver.cpp:416
ThreadedTestHTTPServer::baseUrl
QUrl baseUrl() const
Definition
testhttpserver.cpp:428
ThreadedTestHTTPServer::url
QUrl url(const QString &documentPath) const
Definition
testhttpserver.cpp:433
ThreadedTestHTTPServer::~ThreadedTestHTTPServer
~ThreadedTestHTTPServer()
Definition
testhttpserver.cpp:422
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
ignoredHeaders
static QList< QByteArrayView > ignoredHeaders
Definition
testhttpserver.cpp:58
localHostUrl
static QUrl localHostUrl(quint16 port)
Definition
testhttpserver.cpp:63
qtdeclarative
src
quicktestutils
qml
testhttpserver_p.h
Generated on
for Qt by
1.18.0