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
41
43
47class QByteArray;
48class QHostInfo;
49#ifndef QT_NO_SSL
51class QSslContext;
52#endif // !QT_NO_SSL
53
55class Q_NETWORK_EXPORT QHttpNetworkConnection : public QObject
56{
58public:
59
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);
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
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
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
112public slots:
113 void onlineStateChanged(bool isOnline);
114
115private:
116 Q_DECLARE_PRIVATE(QHttpNetworkConnection)
117 Q_DISABLE_COPY_MOVE(QHttpNetworkConnection)
119 friend class QHttpNetworkReply;
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
133
134
136{
137 Q_DECLARE_PUBLIC(QHttpNetworkConnection)
138 Q_DISABLE_COPY_MOVE(QHttpNetworkConnectionPrivate)
139public:
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
146 RunningState = 0,
147 PausedState = 1
148 };
149
157
158 QHttpNetworkConnectionPrivate(quint16 connectionCount, const QString &hostName, quint16 port,
159 bool encrypt, bool isLocalSocket,
162 void init();
163
164 void pauseConnection();
165 void resumeConnection();
166 ConnectionState state = RunningState;
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
211 bool delayIpv4 = true;
212
213 // Number of channels we are trying to use at the moment:
215 // The total number of channels we reserved:
216 const int channelCount;
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);
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
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
247
248#ifndef QT_NO_SSL
249 std::shared_ptr<QSslContext> sslContext;
250#endif
251
253
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).
263
265};
266
267
268
270
271#endif
IOBluetoothL2CAPChannel * channel
The QAuthenticator class provides an authentication object.
\inmodule QtCore
Definition qbytearray.h:57
The QHostInfo class provides static functions for host name lookups.
Definition qhostinfo.h:19
The QHttp2Configuration class controls HTTP/2 parameters and settings.
QHttpNetworkConnection::ConnectionType connectionType
std::shared_ptr< QSslContext > sslContext
QList< HttpMessagePair > lowPriorityQueue
QList< HttpMessagePair > highPriorityQueue
QHttpNetworkConnectionChannel *const channels
QNetworkConnectionMonitor connectionMonitor
\inmodule QtCore \reentrant
Definition qiodevice.h:34
The QNetworkProxy class provides a network layer proxy.
NetworkError
Indicates all possible error conditions found during the processing of the request.
\inmodule QtCore
Definition qobject.h:103
The QSslConfiguration class holds the configuration and state of an SSL connection.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qtimer.h:20
\inmodule QtCore
Definition qurl.h:94
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
std::pair< T1, T2 > QPair
EGLConfig config
EGLOutputPortEXT port
QPair< QHttpNetworkRequest, QHttpNetworkReply * > HttpMessagePair
GLenum type
void ** params
#define QT_REQUIRE_CONFIG(feature)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
#define Q_OBJECT
#define slots
#define Q_PRIVATE_SLOT(d, signature)
unsigned short quint16
Definition qtypes.h:48
long long qint64
Definition qtypes.h:60
QTcpSocket * socket
[1]
list indexOf("B")
QQueue< int > queue
[0]
QNetworkRequest request(url)
QNetworkReply * reply
reply ignoreSslErrors(expectedSslErrors)
QHostInfo info
[0]
QNetworkProxy proxy
[0]
sslSocket setSslConfiguration(config)