Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qhttpnetworkconnection_p.h
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#ifndef QHTTPNETWORKCONNECTION_H
5
#define QHTTPNETWORKCONNECTION_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 for the convenience
12
// of the Network Access API. This header file may change from
13
// version to version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#include <QtNetwork/private/qtnetworkglobal_p.h>
19
#include <QtNetwork/qnetworkrequest.h>
20
#include <QtNetwork/qnetworkreply.h>
21
#include <QtNetwork/qabstractsocket.h>
22
23
#include <
qhttp2configuration.h
>
24
25
#include <private/qobject_p.h>
26
#include <
qauthenticator.h
>
27
#include <
qnetworkproxy.h
>
28
#include <
qbuffer.h
>
29
#include <
qtimer.h
>
30
#include <
qsharedpointer.h
>
31
32
#include <private/qhttpnetworkheader_p.h>
33
#include <private/qhttpnetworkrequest_p.h>
34
#include <private/qhttpnetworkreply_p.h>
35
#include <private/qnetconmonitor_p.h>
36
#include <private/http2protocol_p.h>
37
38
#include <private/qhttpnetworkconnectionchannel_p.h>
39
40
QT_REQUIRE_CONFIG
(http);
41
42
QT_BEGIN_NAMESPACE
43
44
class
QHttpNetworkRequest
;
45
class
QHttpNetworkReply
;
46
class
QHttpThreadDelegate
;
47
class
QByteArray
;
48
class
QHostInfo
;
49
#ifndef QT_NO_SSL
50
class
QSslConfiguration
;
51
class
QSslContext
;
52
#endif
// !QT_NO_SSL
53
54
class
QHttpNetworkConnectionPrivate
;
55
class
Q_NETWORK_EXPORT
QHttpNetworkConnection
:
public
QObject
56
{
57
Q_OBJECT
58
public
:
59
60
enum
ConnectionType
{
61
ConnectionTypeHTTP
,
62
ConnectionTypeHTTP2
,
63
ConnectionTypeHTTP2Direct
64
};
65
66
QHttpNetworkConnection
(
quint16
channelCount,
const
QString
&hostName,
quint16
port
= 80,
67
bool
encrypt =
false
,
bool
isLocalSocket =
false
,
68
QObject
*parent =
nullptr
,
69
ConnectionType connectionType = ConnectionTypeHTTP);
70
~QHttpNetworkConnection
();
71
72
//The hostname to which this is connected to.
73
QString
hostName()
const
;
74
//The HTTP port in use.
75
quint16
port
()
const
;
76
77
//add a new HTTP request through this connection
78
QHttpNetworkReply
* sendRequest(
const
QHttpNetworkRequest
&
request
);
79
void
fillHttp2Queue();
80
81
#ifndef QT_NO_NETWORKPROXY
82
//set the proxy for this connection
83
void
setCacheProxy(
const
QNetworkProxy
&networkProxy);
84
QNetworkProxy
cacheProxy()
const
;
85
void
setTransparentProxy(
const
QNetworkProxy
&networkProxy);
86
QNetworkProxy
transparentProxy()
const
;
87
#endif
88
89
bool
isSsl()
const
;
90
91
QHttpNetworkConnectionChannel
*channels()
const
;
92
93
ConnectionType connectionType()
const
;
94
void
setConnectionType(ConnectionType
type
);
95
96
QHttp2Configuration
http2Parameters()
const
;
97
void
setHttp2Parameters(
const
QHttp2Configuration
&
params
);
98
99
#ifndef QT_NO_SSL
100
void
setSslConfiguration
(
const
QSslConfiguration
&
config
);
101
void
ignoreSslErrors
(
int
channel
= -1);
102
void
ignoreSslErrors
(
const
QList<QSslError> &errors,
int
channel
= -1);
103
std::shared_ptr<QSslContext> sslContext()
const
;
104
void
setSslContext(std::shared_ptr<QSslContext>
context
);
105
#endif
106
107
void
preConnectFinished();
108
109
QString
peerVerifyName()
const
;
110
void
setPeerVerifyName(
const
QString
&peerName);
111
112
public
slots
:
113
void
onlineStateChanged(
bool
isOnline);
114
115
private
:
116
Q_DECLARE_PRIVATE(
QHttpNetworkConnection
)
117
Q_DISABLE_COPY_MOVE(
QHttpNetworkConnection
)
118
friend class
QHttpThreadDelegate
;
119
friend class
QHttpNetworkReply
;
120
friend class
QHttpNetworkReplyPrivate
;
121
friend class
QHttpNetworkConnectionChannel
;
122
friend class
QHttp2ProtocolHandler
;
123
friend class
QHttpProtocolHandler
;
124
125
Q_PRIVATE_SLOT
(d_func(),
void
_q_startNextRequest())
126
Q_PRIVATE_SLOT
(d_func(),
void
_q_hostLookupFinished(
QHostInfo
))
127
Q_PRIVATE_SLOT
(d_func(),
void
_q_connectDelayedChannel())
128
};
129
130
131
// private classes
132
typedef
QPair
<
QHttpNetworkRequest
,
QHttpNetworkReply
*>
HttpMessagePair
;
133
134
135
class
QHttpNetworkConnectionPrivate
: public
QObjectPrivate
136
{
137
Q_DECLARE_PUBLIC(
QHttpNetworkConnection
)
138
Q_DISABLE_COPY_MOVE(
QHttpNetworkConnectionPrivate
)
139
public
:
140
// Note: Only used from auto tests, normal usage is via QHttp1Configuration
141
static
constexpr
int
defaultHttpChannelCount = 6;
142
static
const
int
defaultPipelineLength
;
143
static
const
int
defaultRePipelineLength
;
144
145
enum
ConnectionState
{
146
RunningState = 0,
147
PausedState = 1
148
};
149
150
enum
NetworkLayerPreferenceState
{
151
Unknown
,
152
HostLookupPending
,
153
IPv4
,
154
IPv6
,
155
IPv4or6
156
};
157
158
QHttpNetworkConnectionPrivate
(
quint16
connectionCount,
const
QString
&hostName,
quint16
port
,
159
bool
encrypt,
bool
isLocalSocket,
160
QHttpNetworkConnection::ConnectionType
type
);
161
~QHttpNetworkConnectionPrivate
();
162
void
init
();
163
164
void
pauseConnection();
165
void
resumeConnection();
166
ConnectionState
state
= RunningState;
167
NetworkLayerPreferenceState
networkLayerState =
Unknown
;
168
169
enum
{ ChunkSize = 4096 };
170
171
int
indexOf
(
QIODevice
*
socket
)
const
;
172
173
QHttpNetworkReply
*queueRequest(
const
QHttpNetworkRequest
&
request
);
174
void
requeueRequest(
const
HttpMessagePair
&pair);
// e.g. after pipeline broke
175
void
fillHttp2Queue();
176
bool
dequeueRequest(
QIODevice
*
socket
);
177
void
prepareRequest(
HttpMessagePair
&
request
);
178
void
updateChannel(
int
i
,
const
HttpMessagePair
&messagePair);
179
QHttpNetworkRequest
predictNextRequest()
const
;
180
QHttpNetworkReply
* predictNextRequestsReply()
const
;
181
182
void
fillPipeline(
QIODevice
*
socket
);
183
bool
fillPipeline(QList<HttpMessagePair> &
queue
,
QHttpNetworkConnectionChannel
&
channel
);
184
185
// read more HTTP body after the next event loop spin
186
void
readMoreLater(
QHttpNetworkReply
*
reply
);
187
188
void
copyCredentials(
int
fromChannel,
QAuthenticator
*auth,
bool
isProxy);
189
190
void
startHostInfoLookup();
191
void
startNetworkLayerStateLookup();
192
void
networkLayerDetected(
QAbstractSocket::NetworkLayerProtocol
protocol);
193
194
// private slots
195
void
_q_startNextRequest();
// send the next request from the queue
196
197
void
_q_hostLookupFinished(
const
QHostInfo
&
info
);
198
void
_q_connectDelayedChannel();
199
200
void
createAuthorization(
QIODevice
*
socket
,
QHttpNetworkRequest
&
request
);
201
202
QString
errorDetail(
QNetworkReply::NetworkError
errorCode,
QIODevice
*
socket
,
203
const
QString
&extraDetail =
QString
());
204
205
void
removeReply(
QHttpNetworkReply
*
reply
);
206
207
QString
hostName
;
208
quint16
port
;
209
bool
encrypt
;
210
bool
isLocalSocket
;
211
bool
delayIpv4 =
true
;
212
213
// Number of channels we are trying to use at the moment:
214
int
activeChannelCount
;
215
// The total number of channels we reserved:
216
const
int
channelCount
;
217
QTimer
delayedConnectionTimer
;
218
QHttpNetworkConnectionChannel
*
const
channels
;
// parallel connections to the server
219
bool
shouldEmitChannelError(
QIODevice
*
socket
);
220
221
qint64
uncompressedBytesAvailable(
const
QHttpNetworkReply
&
reply
)
const
;
222
qint64
uncompressedBytesAvailableNextBlock(
const
QHttpNetworkReply
&
reply
)
const
;
223
224
225
void
emitReplyError(
QIODevice
*
socket
,
QHttpNetworkReply
*
reply
,
QNetworkReply::NetworkError
errorCode);
226
bool
handleAuthenticateChallenge(
QIODevice
*
socket
,
QHttpNetworkReply
*
reply
,
bool
isProxy,
bool
&resend);
227
struct
ParseRedirectResult
{
228
QUrl
redirectUrl
;
229
QNetworkReply::NetworkError
errorCode
;
230
};
231
static
ParseRedirectResult
parseRedirectResponse(
QHttpNetworkReply
*
reply
);
232
// Used by the HTTP1 code-path
233
QUrl
parseRedirectResponse(
QIODevice
*
socket
,
QHttpNetworkReply
*
reply
);
234
235
#ifndef QT_NO_NETWORKPROXY
236
QNetworkProxy
networkProxy
;
237
void
emitProxyAuthenticationRequired(
const
QHttpNetworkConnectionChannel
*chan,
const
QNetworkProxy
&
proxy
,
QAuthenticator
* auth);
238
#endif
239
240
//The request queues
241
QList<HttpMessagePair>
highPriorityQueue
;
242
QList<HttpMessagePair>
lowPriorityQueue
;
243
244
int
preConnectRequests = 0;
245
246
QHttpNetworkConnection::ConnectionType
connectionType
;
247
248
#ifndef QT_NO_SSL
249
std::shared_ptr<QSslContext>
sslContext
;
250
#endif
251
252
QHttp2Configuration
http2Parameters
;
253
254
QString
peerVerifyName
;
255
// If network status monitoring is enabled, we activate connectionMonitor
256
// as soons as one of channels managed to connect to host (and we
257
// have a pair of addresses (us,peer).
258
// NETMONTODO: consider activating a monitor on a change from
259
// HostLookUp state to ConnectingState (means we have both
260
// local/remote addresses known and can start monitoring this
261
// early).
262
QNetworkConnectionMonitor
connectionMonitor
;
263
264
friend
class
QHttpNetworkConnectionChannel
;
265
};
266
267
268
269
QT_END_NAMESPACE
270
271
#endif
channel
IOBluetoothL2CAPChannel * channel
Definition
btl2capchannel.mm:18
QAuthenticator
The QAuthenticator class provides an authentication object.
Definition
qauthenticator.h:18
QByteArray
\inmodule QtCore
Definition
qbytearray.h:57
QHostAddress::NetworkLayerProtocol
NetworkLayerProtocol
Definition
qhostaddress.h:68
QHostInfo
The QHostInfo class provides static functions for host name lookups.
Definition
qhostinfo.h:19
QHttp2Configuration
The QHttp2Configuration class controls HTTP/2 parameters and settings.
Definition
qhttp2configuration.h:17
QHttp2ProtocolHandler
Definition
qhttp2protocolhandler_p.h:47
QHttpNetworkConnectionChannel
Definition
qhttpnetworkconnectionchannel_p.h:61
QHttpNetworkConnectionPrivate
Definition
qhttpnetworkconnection_p.h:136
QHttpNetworkConnectionPrivate::connectionType
QHttpNetworkConnection::ConnectionType connectionType
Definition
qhttpnetworkconnection_p.h:246
QHttpNetworkConnectionPrivate::activeChannelCount
int activeChannelCount
Definition
qhttpnetworkconnection_p.h:214
QHttpNetworkConnectionPrivate::hostName
QString hostName
Definition
qhttpnetworkconnection_p.h:207
QHttpNetworkConnectionPrivate::NetworkLayerPreferenceState
NetworkLayerPreferenceState
Definition
qhttpnetworkconnection_p.h:150
QHttpNetworkConnectionPrivate::HostLookupPending
@ HostLookupPending
Definition
qhttpnetworkconnection_p.h:152
QHttpNetworkConnectionPrivate::IPv6
@ IPv6
Definition
qhttpnetworkconnection_p.h:154
QHttpNetworkConnectionPrivate::IPv4
@ IPv4
Definition
qhttpnetworkconnection_p.h:153
QHttpNetworkConnectionPrivate::Unknown
@ Unknown
Definition
qhttpnetworkconnection_p.h:151
QHttpNetworkConnectionPrivate::ConnectionState
ConnectionState
Definition
qhttpnetworkconnection_p.h:145
QHttpNetworkConnectionPrivate::channelCount
const int channelCount
Definition
qhttpnetworkconnection_p.h:216
QHttpNetworkConnectionPrivate::sslContext
std::shared_ptr< QSslContext > sslContext
Definition
qhttpnetworkconnection_p.h:249
QHttpNetworkConnectionPrivate::defaultRePipelineLength
static const int defaultRePipelineLength
Definition
qhttpnetworkconnection_p.h:143
QHttpNetworkConnectionPrivate::lowPriorityQueue
QList< HttpMessagePair > lowPriorityQueue
Definition
qhttpnetworkconnection_p.h:242
QHttpNetworkConnectionPrivate::peerVerifyName
QString peerVerifyName
Definition
qhttpnetworkconnection_p.h:254
QHttpNetworkConnectionPrivate::highPriorityQueue
QList< HttpMessagePair > highPriorityQueue
Definition
qhttpnetworkconnection_p.h:241
QHttpNetworkConnectionPrivate::port
quint16 port
Definition
qhttpnetworkconnection_p.h:208
QHttpNetworkConnectionPrivate::isLocalSocket
bool isLocalSocket
Definition
qhttpnetworkconnection_p.h:210
QHttpNetworkConnectionPrivate::channels
QHttpNetworkConnectionChannel *const channels
Definition
qhttpnetworkconnection_p.h:218
QHttpNetworkConnectionPrivate::delayedConnectionTimer
QTimer delayedConnectionTimer
Definition
qhttpnetworkconnection_p.h:217
QHttpNetworkConnectionPrivate::http2Parameters
QHttp2Configuration http2Parameters
Definition
qhttpnetworkconnection_p.h:252
QHttpNetworkConnectionPrivate::networkProxy
QNetworkProxy networkProxy
Definition
qhttpnetworkconnection_p.h:236
QHttpNetworkConnectionPrivate::encrypt
bool encrypt
Definition
qhttpnetworkconnection_p.h:209
QHttpNetworkConnectionPrivate::defaultPipelineLength
static const int defaultPipelineLength
Definition
qhttpnetworkconnection_p.h:142
QHttpNetworkConnectionPrivate::connectionMonitor
QNetworkConnectionMonitor connectionMonitor
Definition
qhttpnetworkconnection_p.h:262
QHttpNetworkConnection
Definition
qhttpnetworkconnection_p.h:56
QHttpNetworkConnection::ConnectionType
ConnectionType
Definition
qhttpnetworkconnection_p.h:60
QHttpNetworkConnection::ConnectionTypeHTTP
@ ConnectionTypeHTTP
Definition
qhttpnetworkconnection_p.h:61
QHttpNetworkConnection::ConnectionTypeHTTP2
@ ConnectionTypeHTTP2
Definition
qhttpnetworkconnection_p.h:62
QHttpNetworkReplyPrivate
Definition
qhttpnetworkreply_p.h:171
QHttpNetworkReply
Definition
qhttpnetworkreply_p.h:58
QHttpNetworkRequest
Definition
qhttpnetworkrequest_p.h:33
QHttpProtocolHandler
Definition
qhttpprotocolhandler_p.h:28
QHttpThreadDelegate
Definition
qhttpthreaddelegate_p.h:49
QIODevice
\inmodule QtCore \reentrant
Definition
qiodevice.h:34
QNetworkConnectionMonitor
Definition
qnetconmonitor_p.h:29
QNetworkProxy
The QNetworkProxy class provides a network layer proxy.
Definition
qnetworkproxy.h:79
QNetworkReply::NetworkError
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition
qnetworkreply.h:30
QObjectPrivate
Definition
qobject_p.h:74
QObject
\inmodule QtCore
Definition
qobject.h:103
QSslConfiguration
The QSslConfiguration class holds the configuration and state of an SSL connection.
Definition
qsslconfiguration.h:41
QSslContext
Definition
qsslcontext_openssl_p.h:31
QString
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition
qstring.h:129
QTimer
\inmodule QtCore
Definition
qtimer.h:20
QUrl
\inmodule QtCore
Definition
qurl.h:94
i
i
[1]
Definition
doc_src_containers.cpp:169
state
else opt state
[0]
Definition
doc_src_styles.cpp:11
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qstandardpaths_haiku.cpp:21
QT_END_NAMESPACE
Definition
qsharedpointer.cpp:1590
context
static void * context
Definition
qandroidaudiosource.cpp:42
qauthenticator.h
qbuffer.h
QPair
std::pair< T1, T2 > QPair
Definition
qcontainerfwd.h:28
config
EGLConfig config
Definition
qeglstreamconvenience_p.h:79
port
EGLOutputPortEXT port
Definition
qeglstreamconvenience_p.h:49
qhttp2configuration.h
HttpMessagePair
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
Definition
qhttpnetworkconnection_p.h:132
qnetworkproxy.h
QOcspCertificateStatus::Unknown
@ Unknown
type
GLenum type
Definition
qopengles2ext.h:150
params
void ** params
Definition
qopengles2ext.h:160
qsharedpointer.h
QT_REQUIRE_CONFIG
#define QT_REQUIRE_CONFIG(feature)
Definition
qtconfigmacros.h:67
init
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
Definition
qtextboundaryfinder.cpp:10
qtimer.h
Q_OBJECT
#define Q_OBJECT
Definition
qtmetamacros.h:119
slots
#define slots
Definition
qtmetamacros.h:40
Q_PRIVATE_SLOT
#define Q_PRIVATE_SLOT(d, signature)
Definition
qtmetamacros.h:46
quint16
unsigned short quint16
Definition
qtypes.h:48
qint64
long long qint64
Definition
qtypes.h:60
socket
QTcpSocket * socket
[1]
Definition
src_corelib_kernel_qobject.cpp:392
indexOf
list indexOf("B")
queue
QQueue< int > queue
[0]
Definition
src_corelib_tools_qqueue.cpp:5
request
QNetworkRequest request(url)
reply
QNetworkReply * reply
Definition
src_network_access_qhttpmultipart.cpp:26
ignoreSslErrors
reply ignoreSslErrors(expectedSslErrors)
info
QHostInfo info
[0]
Definition
src_network_kernel_qhostinfo.cpp:14
proxy
QNetworkProxy proxy
[0]
Definition
src_network_kernel_qnetworkproxy.cpp:5
setSslConfiguration
sslSocket setSslConfiguration(config)
QHttpNetworkConnectionPrivate::ParseRedirectResult
Definition
qhttpnetworkconnection_p.h:227
QHttpNetworkConnectionPrivate::ParseRedirectResult::redirectUrl
QUrl redirectUrl
Definition
qhttpnetworkconnection_p.h:228
QHttpNetworkConnectionPrivate::ParseRedirectResult::errorCode
QNetworkReply::NetworkError errorCode
Definition
qhttpnetworkconnection_p.h:229
qtbase
src
network
access
qhttpnetworkconnection_p.h
Generated by
1.10.0