Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkconnection.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qhttpnetworkconnection_p.h" | - | ||||||||||||||||||
35 | #include <private/qabstractsocket_p.h> | - | ||||||||||||||||||
36 | #include "qhttpnetworkconnectionchannel_p.h" | - | ||||||||||||||||||
37 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||||||||
38 | #include <private/qnetworkrequest_p.h> | - | ||||||||||||||||||
39 | #include <private/qobject_p.h> | - | ||||||||||||||||||
40 | #include <private/qauthenticator_p.h> | - | ||||||||||||||||||
41 | #include "private/qhostinfo_p.h" | - | ||||||||||||||||||
42 | #include <qnetworkproxy.h> | - | ||||||||||||||||||
43 | #include <qauthenticator.h> | - | ||||||||||||||||||
44 | #include <qcoreapplication.h> | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | #include <qbuffer.h> | - | ||||||||||||||||||
47 | #include <qpair.h> | - | ||||||||||||||||||
48 | #include <qdebug.h> | - | ||||||||||||||||||
49 | - | |||||||||||||||||||
50 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
53 | # include <private/qsslsocket_p.h> | - | ||||||||||||||||||
54 | # include <QtNetwork/qsslkey.h> | - | ||||||||||||||||||
55 | # include <QtNetwork/qsslcipher.h> | - | ||||||||||||||||||
56 | # include <QtNetwork/qsslconfiguration.h> | - | ||||||||||||||||||
57 | #endif | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | - | |||||||||||||||||||
60 | - | |||||||||||||||||||
61 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | const int QHttpNetworkConnectionPrivate::defaultHttpChannelCount = 6; | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | // The pipeline length. So there will be 4 requests in flight. | - | ||||||||||||||||||
66 | const int QHttpNetworkConnectionPrivate::defaultPipelineLength = 3; | - | ||||||||||||||||||
67 | // Only re-fill the pipeline if there's defaultRePipelineLength slots free in the pipeline. | - | ||||||||||||||||||
68 | // This means that there are 2 requests in flight and 2 slots free that will be re-filled. | - | ||||||||||||||||||
69 | const int QHttpNetworkConnectionPrivate::defaultRePipelineLength = 2; | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | - | |||||||||||||||||||
72 | QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(const QString &hostName, | - | ||||||||||||||||||
73 | quint16 port, bool encrypt, | - | ||||||||||||||||||
74 | QHttpNetworkConnection::ConnectionType type) | - | ||||||||||||||||||
75 | : state(RunningState), | - | ||||||||||||||||||
76 | networkLayerState(Unknown), | - | ||||||||||||||||||
77 | hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true) | - | ||||||||||||||||||
78 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
79 | , channelCount((type == QHttpNetworkConnection::ConnectionTypeSPDY) ? 1 : defaultHttpChannelCount) | - | ||||||||||||||||||
80 | #else | - | ||||||||||||||||||
81 | , channelCount(defaultHttpChannelCount) | - | ||||||||||||||||||
82 | #endif // QT_NO_SSL | - | ||||||||||||||||||
83 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
84 | , networkProxy(QNetworkProxy::NoProxy) | - | ||||||||||||||||||
85 | #endif | - | ||||||||||||||||||
86 | , preConnectRequests(0) | - | ||||||||||||||||||
87 | , connectionType(type) | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | channels = new QHttpNetworkConnectionChannel[channelCount]; | - | ||||||||||||||||||
90 | } executed 575 times by 8 tests: end of block Executed by:
| 575 | ||||||||||||||||||
91 | - | |||||||||||||||||||
92 | QHttpNetworkConnectionPrivate::QHttpNetworkConnectionPrivate(quint16 channelCount, const QString &hostName, | - | ||||||||||||||||||
93 | quint16 port, bool encrypt, | - | ||||||||||||||||||
94 | QHttpNetworkConnection::ConnectionType type) | - | ||||||||||||||||||
95 | : state(RunningState), networkLayerState(Unknown), | - | ||||||||||||||||||
96 | hostName(hostName), port(port), encrypt(encrypt), delayIpv4(true), | - | ||||||||||||||||||
97 | channelCount(channelCount) | - | ||||||||||||||||||
98 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
99 | , networkProxy(QNetworkProxy::NoProxy) | - | ||||||||||||||||||
100 | #endif | - | ||||||||||||||||||
101 | , preConnectRequests(0) | - | ||||||||||||||||||
102 | , connectionType(type) | - | ||||||||||||||||||
103 | { | - | ||||||||||||||||||
104 | channels = new QHttpNetworkConnectionChannel[channelCount]; | - | ||||||||||||||||||
105 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
106 | - | |||||||||||||||||||
107 | - | |||||||||||||||||||
108 | - | |||||||||||||||||||
109 | QHttpNetworkConnectionPrivate::~QHttpNetworkConnectionPrivate() | - | ||||||||||||||||||
110 | { | - | ||||||||||||||||||
111 | for (int i = 0; i < channelCount; ++i) {
| 582-3410 | ||||||||||||||||||
112 | if (channels[i].socket) {
| 751-2659 | ||||||||||||||||||
113 | channels[i].socket->close(); | - | ||||||||||||||||||
114 | delete channels[i].socket; | - | ||||||||||||||||||
115 | } executed 751 times by 9 tests: end of block Executed by:
| 751 | ||||||||||||||||||
116 | } executed 3410 times by 9 tests: end of block Executed by:
| 3410 | ||||||||||||||||||
117 | delete []channels; | - | ||||||||||||||||||
118 | } executed 582 times by 9 tests: end of block Executed by:
| 582 | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | void QHttpNetworkConnectionPrivate::init() | - | ||||||||||||||||||
121 | { | - | ||||||||||||||||||
122 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
123 | for (int i = 0; i < channelCount; i++) {
| 583-3416 | ||||||||||||||||||
124 | channels[i].setConnection(this->q_func()); | - | ||||||||||||||||||
125 | channels[i].ssl = encrypt; | - | ||||||||||||||||||
126 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
127 | //push session down to channels | - | ||||||||||||||||||
128 | channels[i].networkSession = networkSession; | - | ||||||||||||||||||
129 | #endif | - | ||||||||||||||||||
130 | } executed 3416 times by 8 tests: end of block Executed by:
| 3416 | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | delayedConnectionTimer.setSingleShot(true); | - | ||||||||||||||||||
133 | QObject::connect(&delayedConnectionTimer, SIGNAL(timeout()), q, SLOT(_q_connectDelayedChannel())); | - | ||||||||||||||||||
134 | } executed 583 times by 8 tests: end of block Executed by:
| 583 | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | void QHttpNetworkConnectionPrivate::pauseConnection() | - | ||||||||||||||||||
137 | { | - | ||||||||||||||||||
138 | state = PausedState; | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | // Disable all socket notifiers | - | ||||||||||||||||||
141 | for (int i = 0; i < channelCount; i++) {
| 274-1594 | ||||||||||||||||||
142 | if (channels[i].socket) {
| 315-1279 | ||||||||||||||||||
143 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
144 | if (encrypt)
| 118-197 | ||||||||||||||||||
145 | QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); executed 118 times by 3 tests: QSslSocketPrivate::pauseSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); Executed by:
| 118 | ||||||||||||||||||
146 | else | - | ||||||||||||||||||
147 | #endif | - | ||||||||||||||||||
148 | QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket); executed 197 times by 2 tests: QAbstractSocketPrivate::pauseSocketNotifiers(channels[i].socket); Executed by:
| 197 | ||||||||||||||||||
149 | } | - | ||||||||||||||||||
150 | } executed 1594 times by 3 tests: end of block Executed by:
| 1594 | ||||||||||||||||||
151 | } executed 274 times by 3 tests: end of block Executed by:
| 274 | ||||||||||||||||||
152 | - | |||||||||||||||||||
153 | void QHttpNetworkConnectionPrivate::resumeConnection() | - | ||||||||||||||||||
154 | { | - | ||||||||||||||||||
155 | state = RunningState; | - | ||||||||||||||||||
156 | // Enable all socket notifiers | - | ||||||||||||||||||
157 | for (int i = 0; i < channelCount; i++) {
| 274-1594 | ||||||||||||||||||
158 | if (channels[i].socket) {
| 315-1279 | ||||||||||||||||||
159 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
160 | if (encrypt)
| 118-197 | ||||||||||||||||||
161 | QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); executed 118 times by 3 tests: QSslSocketPrivate::resumeSocketNotifiers(static_cast<QSslSocket*>(channels[i].socket)); Executed by:
| 118 | ||||||||||||||||||
162 | else | - | ||||||||||||||||||
163 | #endif | - | ||||||||||||||||||
164 | QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket); executed 197 times by 2 tests: QAbstractSocketPrivate::resumeSocketNotifiers(channels[i].socket); Executed by:
| 197 | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | // Resume pending upload if needed | - | ||||||||||||||||||
167 | if (channels[i].state == QHttpNetworkConnectionChannel::WritingState)
| 0-315 | ||||||||||||||||||
168 | QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); never executed: QMetaObject::invokeMethod(&channels[i], "_q_uploadDataReadyRead", Qt::QueuedConnection); | 0 | ||||||||||||||||||
169 | } executed 315 times by 3 tests: end of block Executed by:
| 315 | ||||||||||||||||||
170 | } executed 1594 times by 3 tests: end of block Executed by:
| 1594 | ||||||||||||||||||
171 | - | |||||||||||||||||||
172 | // queue _q_startNextRequest | - | ||||||||||||||||||
173 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
174 | } executed 274 times by 3 tests: end of block Executed by:
| 274 | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | int QHttpNetworkConnectionPrivate::indexOf(QAbstractSocket *socket) const | - | ||||||||||||||||||
177 | { | - | ||||||||||||||||||
178 | for (int i = 0; i < channelCount; ++i)
| 0-16185 | ||||||||||||||||||
179 | if (channels[i].socket == socket)
| 7321-8864 | ||||||||||||||||||
180 | return i; executed 7321 times by 9 tests: return i; Executed by:
| 7321 | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | qFatal("Called with unknown socket object."); | - | ||||||||||||||||||
183 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
184 | } | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | // If the connection is in the HostLookupPendening state channel errors should not always be | - | ||||||||||||||||||
187 | // emitted. This function will check the status of the connection channels if we | - | ||||||||||||||||||
188 | // have not decided the networkLayerState and will return true if the channel error | - | ||||||||||||||||||
189 | // should be emitted by the channel. | - | ||||||||||||||||||
190 | bool QHttpNetworkConnectionPrivate::shouldEmitChannelError(QAbstractSocket *socket) | - | ||||||||||||||||||
191 | { | - | ||||||||||||||||||
192 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
193 | - | |||||||||||||||||||
194 | bool emitError = true; | - | ||||||||||||||||||
195 | int i = indexOf(socket); | - | ||||||||||||||||||
196 | int otherSocket = (i == 0 ? 1 : 0);
| 27-125 | ||||||||||||||||||
197 | - | |||||||||||||||||||
198 | // If the IPv4 connection still isn't started we need to start it now. | - | ||||||||||||||||||
199 | if (delayedConnectionTimer.isActive()) {
| 30-122 | ||||||||||||||||||
200 | delayedConnectionTimer.stop(); | - | ||||||||||||||||||
201 | channels[otherSocket].ensureConnection(); | - | ||||||||||||||||||
202 | } executed 122 times by 2 tests: end of block Executed by:
| 122 | ||||||||||||||||||
203 | - | |||||||||||||||||||
204 | if (channelCount == 1) {
| 3-149 | ||||||||||||||||||
205 | if (networkLayerState == HostLookupPending || networkLayerState == IPv4or6)
| 0-3 | ||||||||||||||||||
206 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; never executed: networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | 0 | ||||||||||||||||||
207 | channels[0].close(); | - | ||||||||||||||||||
208 | emitError = true; | - | ||||||||||||||||||
209 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
210 | if (networkLayerState == HostLookupPending || networkLayerState == IPv4or6) {
| 0-149 | ||||||||||||||||||
211 | if (channels[otherSocket].isSocketBusy() && (channels[otherSocket].state != QHttpNetworkConnectionChannel::ClosingState)) {
| 0-122 | ||||||||||||||||||
212 | // this was the first socket to fail. | - | ||||||||||||||||||
213 | channels[i].close(); | - | ||||||||||||||||||
214 | emitError = false; | - | ||||||||||||||||||
215 | } executed 122 times by 2 tests: end of block Executed by:
| 122 | ||||||||||||||||||
216 | else { | - | ||||||||||||||||||
217 | // Both connection attempts has failed. | - | ||||||||||||||||||
218 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
219 | channels[i].close(); | - | ||||||||||||||||||
220 | emitError = true; | - | ||||||||||||||||||
221 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||||||||
222 | } else { | - | ||||||||||||||||||
223 | if (((networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (channels[i].networkLayerPreference != QAbstractSocket::IPv4Protocol))
| 0-25 | ||||||||||||||||||
224 | || ((networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (channels[i].networkLayerPreference != QAbstractSocket::IPv6Protocol))) {
| 0-25 | ||||||||||||||||||
225 | // First connection worked so this is the second one to complete and it failed. | - | ||||||||||||||||||
226 | channels[i].close(); | - | ||||||||||||||||||
227 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
228 | emitError = false; | - | ||||||||||||||||||
229 | } never executed: end of block | 0 | ||||||||||||||||||
230 | if (networkLayerState == QHttpNetworkConnectionPrivate::Unknown)
| 0-25 | ||||||||||||||||||
231 | qWarning() << "We got a connection error when networkLayerState is Unknown"; never executed: QMessageLogger(__FILE__, 231, __PRETTY_FUNCTION__).warning() << "We got a connection error when networkLayerState is Unknown"; | 0 | ||||||||||||||||||
232 | } executed 25 times by 2 tests: end of block Executed by:
| 25 | ||||||||||||||||||
233 | } | - | ||||||||||||||||||
234 | return emitError; executed 152 times by 4 tests: return emitError; Executed by:
| 152 | ||||||||||||||||||
235 | } | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | - | |||||||||||||||||||
238 | qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailable(const QHttpNetworkReply &reply) const | - | ||||||||||||||||||
239 | { | - | ||||||||||||||||||
240 | return reply.d_func()->responseData.byteAmount(); executed 23631 times by 1 test: return reply.d_func()->responseData.byteAmount(); Executed by:
| 23631 | ||||||||||||||||||
241 | } | - | ||||||||||||||||||
242 | - | |||||||||||||||||||
243 | qint64 QHttpNetworkConnectionPrivate::uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const | - | ||||||||||||||||||
244 | { | - | ||||||||||||||||||
245 | return reply.d_func()->responseData.sizeNextBlock(); never executed: return reply.d_func()->responseData.sizeNextBlock(); | 0 | ||||||||||||||||||
246 | } | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) | - | ||||||||||||||||||
249 | { | - | ||||||||||||||||||
250 | QHttpNetworkRequest &request = messagePair.first; | - | ||||||||||||||||||
251 | QHttpNetworkReply *reply = messagePair.second; | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | // add missing fields for the request | - | ||||||||||||||||||
254 | QByteArray value; | - | ||||||||||||||||||
255 | // check if Content-Length is provided | - | ||||||||||||||||||
256 | QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); | - | ||||||||||||||||||
257 | if (uploadByteDevice) {
| 201-1437 | ||||||||||||||||||
258 | if (request.contentLength() != -1 && uploadByteDevice->size() != -1) {
| 1-131 | ||||||||||||||||||
259 | // both values known, take the smaller one. | - | ||||||||||||||||||
260 | request.setContentLength(qMin(uploadByteDevice->size(), request.contentLength())); | - | ||||||||||||||||||
261 | } else if (request.contentLength() == -1 && uploadByteDevice->size() != -1) { executed 130 times by 3 tests: end of block Executed by:
| 0-130 | ||||||||||||||||||
262 | // content length not supplied by user, but the upload device knows it | - | ||||||||||||||||||
263 | request.setContentLength(uploadByteDevice->size()); | - | ||||||||||||||||||
264 | } else if (request.contentLength() != -1 && uploadByteDevice->size() == -1) { executed 70 times by 2 tests: end of block Executed by:
| 0-70 | ||||||||||||||||||
265 | // everything OK, the user supplied us the contentLength | - | ||||||||||||||||||
266 | } else if (request.contentLength() == -1 && uploadByteDevice->size() == -1) { executed 1 time by 1 test: end of block Executed by:
| 0-1 | ||||||||||||||||||
267 | qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given"); | - | ||||||||||||||||||
268 | } never executed: end of block | 0 | ||||||||||||||||||
269 | } executed 201 times by 4 tests: end of block Executed by:
| 201 | ||||||||||||||||||
270 | // set the Connection/Proxy-Connection: Keep-Alive headers | - | ||||||||||||||||||
271 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
272 | if (networkProxy.type() == QNetworkProxy::HttpCachingProxy) {
| 8-1630 | ||||||||||||||||||
273 | value = request.headerField("proxy-connection"); | - | ||||||||||||||||||
274 | if (value.isEmpty())
| 0-8 | ||||||||||||||||||
275 | request.setHeaderField("Proxy-Connection", "Keep-Alive"); executed 8 times by 1 test: request.setHeaderField("Proxy-Connection", "Keep-Alive"); Executed by:
| 8 | ||||||||||||||||||
276 | } else { executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
277 | #endif | - | ||||||||||||||||||
278 | value = request.headerField("connection"); | - | ||||||||||||||||||
279 | if (value.isEmpty())
| 0-1630 | ||||||||||||||||||
280 | request.setHeaderField("Connection", "Keep-Alive"); executed 1630 times by 9 tests: request.setHeaderField("Connection", "Keep-Alive"); Executed by:
| 1630 | ||||||||||||||||||
281 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
282 | } executed 1630 times by 9 tests: end of block Executed by:
| 1630 | ||||||||||||||||||
283 | #endif | - | ||||||||||||||||||
284 | - | |||||||||||||||||||
285 | // If the request had a accept-encoding set, we better not mess | - | ||||||||||||||||||
286 | // with it. If it was not set, we announce that we understand gzip | - | ||||||||||||||||||
287 | // and remember this fact in request.d->autoDecompress so that | - | ||||||||||||||||||
288 | // we can later decompress the HTTP reply if it has such an | - | ||||||||||||||||||
289 | // encoding. | - | ||||||||||||||||||
290 | value = request.headerField("accept-encoding"); | - | ||||||||||||||||||
291 | if (value.isEmpty()) {
| 2-1636 | ||||||||||||||||||
292 | #ifndef QT_NO_COMPRESS | - | ||||||||||||||||||
293 | request.setHeaderField("Accept-Encoding", "gzip, deflate"); | - | ||||||||||||||||||
294 | request.d->autoDecompress = true; | - | ||||||||||||||||||
295 | #else | - | ||||||||||||||||||
296 | // if zlib is not available set this to false always | - | ||||||||||||||||||
297 | request.d->autoDecompress = false; | - | ||||||||||||||||||
298 | #endif | - | ||||||||||||||||||
299 | } executed 1636 times by 9 tests: end of block Executed by:
| 1636 | ||||||||||||||||||
300 | - | |||||||||||||||||||
301 | // some websites mandate an accept-language header and fail | - | ||||||||||||||||||
302 | // if it is not sent. This is a problem with the website and | - | ||||||||||||||||||
303 | // not with us, but we work around this by setting | - | ||||||||||||||||||
304 | // one always. | - | ||||||||||||||||||
305 | value = request.headerField("accept-language"); | - | ||||||||||||||||||
306 | if (value.isEmpty()) {
| 0-1638 | ||||||||||||||||||
307 | QString systemLocale = QLocale::system().name().replace(QChar::fromLatin1('_'),QChar::fromLatin1('-')); | - | ||||||||||||||||||
308 | QString acceptLanguage; | - | ||||||||||||||||||
309 | if (systemLocale == QLatin1String("C"))
| 0-1638 | ||||||||||||||||||
310 | acceptLanguage = QString::fromLatin1("en,*"); never executed: acceptLanguage = QString::fromLatin1("en,*"); | 0 | ||||||||||||||||||
311 | else if (systemLocale.startsWith(QLatin1String("en-")))
| 0-1638 | ||||||||||||||||||
312 | acceptLanguage = QString::fromLatin1("%1,*").arg(systemLocale); executed 1638 times by 9 tests: acceptLanguage = QString::fromLatin1("%1,*").arg(systemLocale); Executed by:
| 1638 | ||||||||||||||||||
313 | else | - | ||||||||||||||||||
314 | acceptLanguage = QString::fromLatin1("%1,en,*").arg(systemLocale); never executed: acceptLanguage = QString::fromLatin1("%1,en,*").arg(systemLocale); | 0 | ||||||||||||||||||
315 | request.setHeaderField("Accept-Language", acceptLanguage.toLatin1()); | - | ||||||||||||||||||
316 | } executed 1638 times by 9 tests: end of block Executed by:
| 1638 | ||||||||||||||||||
317 | - | |||||||||||||||||||
318 | // set the User Agent | - | ||||||||||||||||||
319 | value = request.headerField("user-agent"); | - | ||||||||||||||||||
320 | if (value.isEmpty())
| 4-1634 | ||||||||||||||||||
321 | request.setHeaderField("User-Agent", "Mozilla/5.0"); executed 1634 times by 8 tests: request.setHeaderField("User-Agent", "Mozilla/5.0"); Executed by:
| 1634 | ||||||||||||||||||
322 | // set the host | - | ||||||||||||||||||
323 | value = request.headerField("host"); | - | ||||||||||||||||||
324 | if (value.isEmpty()) {
| 1-1637 | ||||||||||||||||||
325 | QHostAddress add; | - | ||||||||||||||||||
326 | QByteArray host; | - | ||||||||||||||||||
327 | if (add.setAddress(hostName)) {
| 43-1594 | ||||||||||||||||||
328 | if (add.protocol() == QAbstractSocket::IPv6Protocol)
| 1-42 | ||||||||||||||||||
329 | host = '[' + hostName.toLatin1() + ']'; //format the ipv6 in the standard way executed 1 time by 1 test: host = '[' + hostName.toLatin1() + ']'; Executed by:
| 1 | ||||||||||||||||||
330 | else | - | ||||||||||||||||||
331 | host = hostName.toLatin1(); executed 42 times by 3 tests: host = hostName.toLatin1(); Executed by:
| 42 | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | } else { | - | ||||||||||||||||||
334 | host = QUrl::toAce(hostName); | - | ||||||||||||||||||
335 | } executed 1594 times by 8 tests: end of block Executed by:
| 1594 | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | int port = request.url().port(); | - | ||||||||||||||||||
338 | if (port != -1) {
| 174-1463 | ||||||||||||||||||
339 | host += ':'; | - | ||||||||||||||||||
340 | host += QByteArray::number(port); | - | ||||||||||||||||||
341 | } executed 174 times by 4 tests: end of block Executed by:
| 174 | ||||||||||||||||||
342 | - | |||||||||||||||||||
343 | request.setHeaderField("Host", host); | - | ||||||||||||||||||
344 | } executed 1637 times by 8 tests: end of block Executed by:
| 1637 | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | reply->d_func()->requestIsPrepared = true; | - | ||||||||||||||||||
347 | } executed 1638 times by 9 tests: end of block Executed by:
| 1638 | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | - | |||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, | - | ||||||||||||||||||
353 | QHttpNetworkReply *reply, | - | ||||||||||||||||||
354 | QNetworkReply::NetworkError errorCode) | - | ||||||||||||||||||
355 | { | - | ||||||||||||||||||
356 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
357 | - | |||||||||||||||||||
358 | int i = 0; | - | ||||||||||||||||||
359 | if (socket)
| 4-5 | ||||||||||||||||||
360 | i = indexOf(socket); executed 5 times by 2 tests: i = indexOf(socket); Executed by:
| 5 | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | if (reply) {
| 0-9 | ||||||||||||||||||
363 | // this error matters only to this reply | - | ||||||||||||||||||
364 | reply->d_func()->errorString = errorDetail(errorCode, socket); | - | ||||||||||||||||||
365 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
366 | // remove the corrupt data if any | - | ||||||||||||||||||
367 | reply->d_func()->eraseData(); | - | ||||||||||||||||||
368 | - | |||||||||||||||||||
369 | // Clean the channel | - | ||||||||||||||||||
370 | channels[i].close(); | - | ||||||||||||||||||
371 | channels[i].reply = 0; | - | ||||||||||||||||||
372 | if (channels[i].protocolHandler)
| 4-5 | ||||||||||||||||||
373 | channels[i].protocolHandler->setReply(0); executed 5 times by 2 tests: channels[i].protocolHandler->setReply(0); Executed by:
| 5 | ||||||||||||||||||
374 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||
375 | if (socket)
| 4-5 | ||||||||||||||||||
376 | channels[i].requeueCurrentlyPipelinedRequests(); executed 5 times by 2 tests: channels[i].requeueCurrentlyPipelinedRequests(); Executed by:
| 5 | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | // send the next request | - | ||||||||||||||||||
379 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
380 | } executed 9 times by 4 tests: end of block Executed by:
| 9 | ||||||||||||||||||
381 | } executed 9 times by 4 tests: end of block Executed by:
| 9 | ||||||||||||||||||
382 | - | |||||||||||||||||||
383 | void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthenticator *auth, bool isProxy) | - | ||||||||||||||||||
384 | { | - | ||||||||||||||||||
385 | Q_ASSERT(auth); | - | ||||||||||||||||||
386 | - | |||||||||||||||||||
387 | // NTLM is a multi phase authentication. Copying credentials between authenticators would mess things up. | - | ||||||||||||||||||
388 | if (fromChannel >= 0) {
| 0-201 | ||||||||||||||||||
389 | if (!isProxy && channels[fromChannel].authMethod == QAuthenticatorPrivate::Ntlm)
| 0-135 | ||||||||||||||||||
390 | return; never executed: return; | 0 | ||||||||||||||||||
391 | if (isProxy && channels[fromChannel].proxyAuthMethod == QAuthenticatorPrivate::Ntlm)
| 0-135 | ||||||||||||||||||
392 | return; never executed: return; | 0 | ||||||||||||||||||
393 | } executed 201 times by 3 tests: end of block Executed by:
| 201 | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | // select another channel | - | ||||||||||||||||||
396 | QAuthenticator* otherAuth = 0; | - | ||||||||||||||||||
397 | for (int i = 0; i < channelCount; ++i) {
| 201-1191 | ||||||||||||||||||
398 | if (i == fromChannel)
| 201-990 | ||||||||||||||||||
399 | continue; executed 201 times by 3 tests: continue; Executed by:
| 201 | ||||||||||||||||||
400 | if (isProxy)
| 315-675 | ||||||||||||||||||
401 | otherAuth = &channels[i].proxyAuthenticator; executed 315 times by 1 test: otherAuth = &channels[i].proxyAuthenticator; Executed by:
| 315 | ||||||||||||||||||
402 | else | - | ||||||||||||||||||
403 | otherAuth = &channels[i].authenticator; executed 675 times by 2 tests: otherAuth = &channels[i].authenticator; Executed by:
| 675 | ||||||||||||||||||
404 | // if the credentials are different, copy them | - | ||||||||||||||||||
405 | if (otherAuth->user().compare(auth->user()))
| 255-735 | ||||||||||||||||||
406 | otherAuth->setUser(auth->user()); executed 735 times by 2 tests: otherAuth->setUser(auth->user()); Executed by:
| 735 | ||||||||||||||||||
407 | if (otherAuth->password().compare(auth->password()))
| 245-745 | ||||||||||||||||||
408 | otherAuth->setPassword(auth->password()); executed 745 times by 2 tests: otherAuth->setPassword(auth->password()); Executed by:
| 745 | ||||||||||||||||||
409 | } executed 990 times by 2 tests: end of block Executed by:
| 990 | ||||||||||||||||||
410 | } executed 201 times by 3 tests: end of block Executed by:
| 201 | ||||||||||||||||||
411 | - | |||||||||||||||||||
412 | - | |||||||||||||||||||
413 | // handles the authentication for one channel and eventually re-starts the other channels | - | ||||||||||||||||||
414 | bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, | - | ||||||||||||||||||
415 | bool isProxy, bool &resend) | - | ||||||||||||||||||
416 | { | - | ||||||||||||||||||
417 | Q_ASSERT(socket); | - | ||||||||||||||||||
418 | Q_ASSERT(reply); | - | ||||||||||||||||||
419 | - | |||||||||||||||||||
420 | resend = false; | - | ||||||||||||||||||
421 | //create the response header to be used with QAuthenticatorPrivate. | - | ||||||||||||||||||
422 | QList<QPair<QByteArray, QByteArray> > fields = reply->header(); | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | //find out the type of authentication protocol requested. | - | ||||||||||||||||||
425 | QAuthenticatorPrivate::Method authMethod = reply->d_func()->authenticationMethod(isProxy); | - | ||||||||||||||||||
426 | if (authMethod != QAuthenticatorPrivate::None) {
| 3-353 | ||||||||||||||||||
427 | int i = indexOf(socket); | - | ||||||||||||||||||
428 | //Use a single authenticator for all domains. ### change later to use domain/realm | - | ||||||||||||||||||
429 | QAuthenticator* auth = 0; | - | ||||||||||||||||||
430 | if (isProxy) {
| 53-300 | ||||||||||||||||||
431 | auth = &channels[i].proxyAuthenticator; | - | ||||||||||||||||||
432 | channels[i].proxyAuthMethod = authMethod; | - | ||||||||||||||||||
433 | } else { executed 53 times by 1 test: end of block Executed by:
| 53 | ||||||||||||||||||
434 | auth = &channels[i].authenticator; | - | ||||||||||||||||||
435 | channels[i].authMethod = authMethod; | - | ||||||||||||||||||
436 | } executed 300 times by 2 tests: end of block Executed by:
| 300 | ||||||||||||||||||
437 | //proceed with the authentication. | - | ||||||||||||||||||
438 | if (auth->isNull())
| 0-353 | ||||||||||||||||||
439 | auth->detach(); never executed: auth->detach(); | 0 | ||||||||||||||||||
440 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
441 | priv->parseHttpResponse(fields, isProxy); | - | ||||||||||||||||||
442 | - | |||||||||||||||||||
443 | if (priv->phase == QAuthenticatorPrivate::Done) {
| 174-179 | ||||||||||||||||||
444 | pauseConnection(); | - | ||||||||||||||||||
445 | if (!isProxy) {
| 27-152 | ||||||||||||||||||
446 | if (channels[i].authenticationCredentialsSent) {
| 52-100 | ||||||||||||||||||
447 | auth->detach(); | - | ||||||||||||||||||
448 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
449 | priv->hasFailed = true; | - | ||||||||||||||||||
450 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||
451 | channels[i].authenticationCredentialsSent = false; | - | ||||||||||||||||||
452 | } executed 52 times by 2 tests: end of block Executed by:
| 52 | ||||||||||||||||||
453 | emit reply->authenticationRequired(reply->request(), auth); | - | ||||||||||||||||||
454 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
455 | } else { executed 152 times by 2 tests: end of block Executed by:
| 152 | ||||||||||||||||||
456 | if (channels[i].proxyCredentialsSent) {
| 2-25 | ||||||||||||||||||
457 | auth->detach(); | - | ||||||||||||||||||
458 | priv = QAuthenticatorPrivate::getPrivate(*auth); | - | ||||||||||||||||||
459 | priv->hasFailed = true; | - | ||||||||||||||||||
460 | priv->phase = QAuthenticatorPrivate::Done; | - | ||||||||||||||||||
461 | channels[i].proxyCredentialsSent = false; | - | ||||||||||||||||||
462 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
463 | emit reply->proxyAuthenticationRequired(networkProxy, auth); | - | ||||||||||||||||||
464 | #endif | - | ||||||||||||||||||
465 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||
466 | resumeConnection(); | - | ||||||||||||||||||
467 | - | |||||||||||||||||||
468 | if (priv->phase != QAuthenticatorPrivate::Done) {
| 38-141 | ||||||||||||||||||
469 | // send any pending requests | - | ||||||||||||||||||
470 | copyCredentials(i, auth, isProxy); | - | ||||||||||||||||||
471 | } executed 141 times by 2 tests: end of block Executed by:
| 141 | ||||||||||||||||||
472 | } else if (priv->phase == QAuthenticatorPrivate::Start) { executed 179 times by 2 tests: end of block Executed by:
| 0-179 | ||||||||||||||||||
473 | // If the url's authenticator has a 'user' set we will end up here (phase is only set to 'Done' by | - | ||||||||||||||||||
474 | // parseHttpResponse above if 'user' is empty). So if credentials were supplied with the request, | - | ||||||||||||||||||
475 | // such as in the case of an XMLHttpRequest, this is our only opportunity to cache them. | - | ||||||||||||||||||
476 | emit reply->cacheCredentials(reply->request(), auth); | - | ||||||||||||||||||
477 | } executed 174 times by 2 tests: end of block Executed by:
| 174 | ||||||||||||||||||
478 | // - Changing values in QAuthenticator will reset the 'phase'. Therefore if it is still "Done" | - | ||||||||||||||||||
479 | // then nothing was filled in by the user or the cache | - | ||||||||||||||||||
480 | // - If withCredentials has been set to false (e.g. by Qt WebKit for a cross-origin XMLHttpRequest) then | - | ||||||||||||||||||
481 | // we need to bail out if authentication is required. | - | ||||||||||||||||||
482 | if (priv->phase == QAuthenticatorPrivate::Done || !reply->request().withCredentials()) {
| 0-315 | ||||||||||||||||||
483 | // Reset authenticator so the next request on that channel does not get messed up | - | ||||||||||||||||||
484 | auth = 0; | - | ||||||||||||||||||
485 | if (isProxy)
| 3-35 | ||||||||||||||||||
486 | channels[i].proxyAuthenticator = QAuthenticator(); executed 3 times by 1 test: channels[i].proxyAuthenticator = QAuthenticator(); Executed by:
| 3 | ||||||||||||||||||
487 | else | - | ||||||||||||||||||
488 | channels[i].authenticator = QAuthenticator(); executed 35 times by 2 tests: channels[i].authenticator = QAuthenticator(); Executed by:
| 35 | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | // authentication is cancelled, send the current contents to the user. | - | ||||||||||||||||||
491 | emit channels[i].reply->headerChanged(); | - | ||||||||||||||||||
492 | emit channels[i].reply->readyRead(); | - | ||||||||||||||||||
493 | QNetworkReply::NetworkError errorCode = | - | ||||||||||||||||||
494 | isProxy
| 3-35 | ||||||||||||||||||
495 | ? QNetworkReply::ProxyAuthenticationRequiredError | - | ||||||||||||||||||
496 | : QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||||||||
497 | reply->d_func()->errorString = errorDetail(errorCode, socket); | - | ||||||||||||||||||
498 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
499 | // ### at this point the reply could be deleted | - | ||||||||||||||||||
500 | return true; executed 38 times by 2 tests: return true; Executed by:
| 38 | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | //resend the request | - | ||||||||||||||||||
503 | resend = true; | - | ||||||||||||||||||
504 | return true; executed 315 times by 2 tests: return true; Executed by:
| 315 | ||||||||||||||||||
505 | } | - | ||||||||||||||||||
506 | return false; executed 3 times by 1 test: return false; Executed by:
| 3 | ||||||||||||||||||
507 | } | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | QUrl QHttpNetworkConnectionPrivate::parseRedirectResponse(QAbstractSocket *socket, QHttpNetworkReply *reply) | - | ||||||||||||||||||
510 | { | - | ||||||||||||||||||
511 | if (!reply->request().isFollowRedirects())
| 3-7 | ||||||||||||||||||
512 | return QUrl(); executed 3 times by 1 test: return QUrl(); Executed by:
| 3 | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | QUrl rUrl; | - | ||||||||||||||||||
515 | QList<QPair<QByteArray, QByteArray> > fields = reply->header(); | - | ||||||||||||||||||
516 | foreach (const QNetworkReply::RawHeaderPair &header, fields) { | - | ||||||||||||||||||
517 | if (header.first.toLower() == "location") {
| 7 | ||||||||||||||||||
518 | rUrl = QUrl::fromEncoded(header.second); | - | ||||||||||||||||||
519 | break; executed 7 times by 2 tests: break; Executed by:
| 7 | ||||||||||||||||||
520 | } | - | ||||||||||||||||||
521 | } executed 7 times by 2 tests: end of block Executed by:
| 7 | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | // If the location url is invalid/empty, we emit ProtocolUnknownError | - | ||||||||||||||||||
524 | if (!rUrl.isValid()) {
| 0-7 | ||||||||||||||||||
525 | emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
526 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
527 | } | - | ||||||||||||||||||
528 | - | |||||||||||||||||||
529 | // Check if we have exceeded max redirects allowed | - | ||||||||||||||||||
530 | if (reply->request().redirectCount() <= 0) {
| 1-6 | ||||||||||||||||||
531 | emitReplyError(socket, reply, QNetworkReply::TooManyRedirectsError); | - | ||||||||||||||||||
532 | return QUrl(); executed 1 time by 1 test: return QUrl(); Executed by:
| 1 | ||||||||||||||||||
533 | } | - | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | // Resolve the URL if it's relative | - | ||||||||||||||||||
536 | if (rUrl.isRelative())
| 0-6 | ||||||||||||||||||
537 | rUrl = reply->request().url().resolved(rUrl); never executed: rUrl = reply->request().url().resolved(rUrl); | 0 | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | // Check redirect url protocol | - | ||||||||||||||||||
540 | QString scheme = rUrl.scheme(); | - | ||||||||||||||||||
541 | if (scheme == QLatin1String("http") || scheme == QLatin1String("https")) {
| 0-6 | ||||||||||||||||||
542 | QString previousUrlScheme = reply->request().url().scheme(); | - | ||||||||||||||||||
543 | // Check if we're doing an unsecure redirect (https -> http) | - | ||||||||||||||||||
544 | if (previousUrlScheme == QLatin1String("https")
| 0-6 | ||||||||||||||||||
545 | && scheme == QLatin1String("http")) {
| 0 | ||||||||||||||||||
546 | emitReplyError(socket, reply, QNetworkReply::InsecureRedirectError); | - | ||||||||||||||||||
547 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
548 | } | - | ||||||||||||||||||
549 | } else { executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
550 | emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
551 | return QUrl(); never executed: return QUrl(); | 0 | ||||||||||||||||||
552 | } | - | ||||||||||||||||||
553 | return rUrl; executed 6 times by 2 tests: return rUrl; Executed by:
| 6 | ||||||||||||||||||
554 | } | - | ||||||||||||||||||
555 | - | |||||||||||||||||||
556 | void QHttpNetworkConnectionPrivate::createAuthorization(QAbstractSocket *socket, QHttpNetworkRequest &request) | - | ||||||||||||||||||
557 | { | - | ||||||||||||||||||
558 | Q_ASSERT(socket); | - | ||||||||||||||||||
559 | - | |||||||||||||||||||
560 | int i = indexOf(socket); | - | ||||||||||||||||||
561 | - | |||||||||||||||||||
562 | // Send "Authorization" header, but not if it's NTLM and the socket is already authenticated. | - | ||||||||||||||||||
563 | if (channels[i].authMethod != QAuthenticatorPrivate::None) {
| 172-1152 | ||||||||||||||||||
564 | if ((channels[i].authMethod != QAuthenticatorPrivate::Ntlm && request.headerField("Authorization").isEmpty()) || channels[i].lastStatus == 401) {
| 0-172 | ||||||||||||||||||
565 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].authenticator); | - | ||||||||||||||||||
566 | if (priv && priv->method != QAuthenticatorPrivate::None) {
| 0-172 | ||||||||||||||||||
567 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||
568 | request.setHeaderField("Authorization", response); | - | ||||||||||||||||||
569 | channels[i].authenticationCredentialsSent = true; | - | ||||||||||||||||||
570 | } executed 152 times by 2 tests: end of block Executed by:
| 152 | ||||||||||||||||||
571 | } executed 172 times by 2 tests: end of block Executed by:
| 172 | ||||||||||||||||||
572 | } executed 172 times by 2 tests: end of block Executed by:
| 172 | ||||||||||||||||||
573 | - | |||||||||||||||||||
574 | // Send "Proxy-Authorization" header, but not if it's NTLM and the socket is already authenticated. | - | ||||||||||||||||||
575 | if (channels[i].proxyAuthMethod != QAuthenticatorPrivate::None) {
| 40-1284 | ||||||||||||||||||
576 | if (!(channels[i].proxyAuthMethod == QAuthenticatorPrivate::Ntlm && channels[i].lastStatus != 407)) {
| 0-40 | ||||||||||||||||||
577 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(channels[i].proxyAuthenticator); | - | ||||||||||||||||||
578 | if (priv && priv->method != QAuthenticatorPrivate::None) {
| 0-40 | ||||||||||||||||||
579 | QByteArray response = priv->calculateResponse(request.methodName(), request.uri(false)); | - | ||||||||||||||||||
580 | request.setHeaderField("Proxy-Authorization", response); | - | ||||||||||||||||||
581 | channels[i].proxyCredentialsSent = true; | - | ||||||||||||||||||
582 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||||||||
583 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||
584 | } executed 40 times by 1 test: end of block Executed by:
| 40 | ||||||||||||||||||
585 | } executed 1324 times by 9 tests: end of block Executed by:
| 1324 | ||||||||||||||||||
586 | - | |||||||||||||||||||
587 | QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetworkRequest &request) | - | ||||||||||||||||||
588 | { | - | ||||||||||||||||||
589 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | // The reply component of the pair is created initially. | - | ||||||||||||||||||
592 | QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); | - | ||||||||||||||||||
593 | reply->setRequest(request); | - | ||||||||||||||||||
594 | reply->d_func()->connection = q; | - | ||||||||||||||||||
595 | reply->d_func()->connectionChannel = &channels[0]; // will have the correct one set later | - | ||||||||||||||||||
596 | HttpMessagePair pair = qMakePair(request, reply); | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | if (request.isPreConnect())
| 0-1646 | ||||||||||||||||||
599 | preConnectRequests++; never executed: preConnectRequests++; | 0 | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 112-1534 | ||||||||||||||||||
602 | switch (request.priority()) { | - | ||||||||||||||||||
603 | case QHttpNetworkRequest::HighPriority: executed 116 times by 1 test: case QHttpNetworkRequest::HighPriority: Executed by:
| 116 | ||||||||||||||||||
604 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||
605 | break; executed 116 times by 1 test: break; Executed by:
| 116 | ||||||||||||||||||
606 | case QHttpNetworkRequest::NormalPriority: executed 1362 times by 8 tests: case QHttpNetworkRequest::NormalPriority: Executed by:
| 1362 | ||||||||||||||||||
607 | case QHttpNetworkRequest::LowPriority: executed 56 times by 1 test: case QHttpNetworkRequest::LowPriority: Executed by:
| 56 | ||||||||||||||||||
608 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||
609 | break; executed 1418 times by 8 tests: break; Executed by:
| 1418 | ||||||||||||||||||
610 | } | - | ||||||||||||||||||
611 | } executed 1534 times by 8 tests: end of block Executed by:
| 1534 | ||||||||||||||||||
612 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
613 | else { // SPDY | - | ||||||||||||||||||
614 | if (!pair.second->d_func()->requestIsPrepared)
| 0-112 | ||||||||||||||||||
615 | prepareRequest(pair); executed 112 times by 1 test: prepareRequest(pair); Executed by:
| 112 | ||||||||||||||||||
616 | channels[0].spdyRequestsToSend.insertMulti(request.priority(), pair); | - | ||||||||||||||||||
617 | } executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||||||||
618 | #endif // QT_NO_SSL | - | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | // For Happy Eyeballs the networkLayerState is set to Unknown | - | ||||||||||||||||||
621 | // untill we have started the first connection attempt. So no | - | ||||||||||||||||||
622 | // request will be started untill we know if IPv4 or IPv6 | - | ||||||||||||||||||
623 | // should be used. | - | ||||||||||||||||||
624 | if (networkLayerState == Unknown || networkLayerState == HostLookupPending) {
| 0-1063 | ||||||||||||||||||
625 | startHostInfoLookup(); | - | ||||||||||||||||||
626 | } else if ( networkLayerState == IPv4 || networkLayerState == IPv6 ) { executed 583 times by 8 tests: end of block Executed by:
| 0-1061 | ||||||||||||||||||
627 | // this used to be called via invokeMethod and a QueuedConnection | - | ||||||||||||||||||
628 | // It is the only place _q_startNextRequest is called directly without going | - | ||||||||||||||||||
629 | // through the event loop using a QueuedConnection. | - | ||||||||||||||||||
630 | // This is dangerous because of recursion that might occur when emitting | - | ||||||||||||||||||
631 | // signals as DirectConnection from this code path. Therefore all signal | - | ||||||||||||||||||
632 | // emissions that can come out from this code path need to | - | ||||||||||||||||||
633 | // be QueuedConnection. | - | ||||||||||||||||||
634 | // We are currently trying to fine-tune this. | - | ||||||||||||||||||
635 | _q_startNextRequest(); | - | ||||||||||||||||||
636 | } executed 1061 times by 4 tests: end of block Executed by:
| 1061 | ||||||||||||||||||
637 | return reply; executed 1646 times by 8 tests: return reply; Executed by:
| 1646 | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | void QHttpNetworkConnectionPrivate::requeueRequest(const HttpMessagePair &pair) | - | ||||||||||||||||||
641 | { | - | ||||||||||||||||||
642 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | QHttpNetworkRequest request = pair.first; | - | ||||||||||||||||||
645 | switch (request.priority()) { | - | ||||||||||||||||||
646 | case QHttpNetworkRequest::HighPriority: never executed: case QHttpNetworkRequest::HighPriority: | 0 | ||||||||||||||||||
647 | highPriorityQueue.prepend(pair); | - | ||||||||||||||||||
648 | break; never executed: break; | 0 | ||||||||||||||||||
649 | case QHttpNetworkRequest::NormalPriority: never executed: case QHttpNetworkRequest::NormalPriority: | 0 | ||||||||||||||||||
650 | case QHttpNetworkRequest::LowPriority: never executed: case QHttpNetworkRequest::LowPriority: | 0 | ||||||||||||||||||
651 | lowPriorityQueue.prepend(pair); | - | ||||||||||||||||||
652 | break; never executed: break; | 0 | ||||||||||||||||||
653 | } | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
656 | } never executed: end of block | 0 | ||||||||||||||||||
657 | - | |||||||||||||||||||
658 | bool QHttpNetworkConnectionPrivate::dequeueRequest(QAbstractSocket *socket) | - | ||||||||||||||||||
659 | { | - | ||||||||||||||||||
660 | int i = 0; | - | ||||||||||||||||||
661 | if (socket)
| 4-1157 | ||||||||||||||||||
662 | i = indexOf(socket); executed 1157 times by 9 tests: i = indexOf(socket); Executed by:
| 1157 | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | if (!highPriorityQueue.isEmpty()) {
| 54-1107 | ||||||||||||||||||
665 | // remove from queue before sendRequest! else we might pipeline the same request again | - | ||||||||||||||||||
666 | HttpMessagePair messagePair = highPriorityQueue.takeLast(); | - | ||||||||||||||||||
667 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-54 | ||||||||||||||||||
668 | prepareRequest(messagePair); executed 54 times by 1 test: prepareRequest(messagePair); Executed by:
| 54 | ||||||||||||||||||
669 | updateChannel(i, messagePair); | - | ||||||||||||||||||
670 | return true; executed 54 times by 1 test: return true; Executed by:
| 54 | ||||||||||||||||||
671 | } | - | ||||||||||||||||||
672 | - | |||||||||||||||||||
673 | if (!lowPriorityQueue.isEmpty()) {
| 36-1071 | ||||||||||||||||||
674 | // remove from queue before sendRequest! else we might pipeline the same request again | - | ||||||||||||||||||
675 | HttpMessagePair messagePair = lowPriorityQueue.takeLast(); | - | ||||||||||||||||||
676 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-1071 | ||||||||||||||||||
677 | prepareRequest(messagePair); executed 1071 times by 9 tests: prepareRequest(messagePair); Executed by:
| 1071 | ||||||||||||||||||
678 | updateChannel(i, messagePair); | - | ||||||||||||||||||
679 | return true; executed 1071 times by 9 tests: return true; Executed by:
| 1071 | ||||||||||||||||||
680 | } | - | ||||||||||||||||||
681 | return false; executed 36 times by 3 tests: return false; Executed by:
| 36 | ||||||||||||||||||
682 | } | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | void QHttpNetworkConnectionPrivate::updateChannel(int i, const HttpMessagePair &messagePair) | - | ||||||||||||||||||
685 | { | - | ||||||||||||||||||
686 | channels[i].request = messagePair.first; | - | ||||||||||||||||||
687 | channels[i].reply = messagePair.second; | - | ||||||||||||||||||
688 | // Now that reply is assigned a channel, correct reply to channel association | - | ||||||||||||||||||
689 | // previously set in queueRequest. | - | ||||||||||||||||||
690 | channels[i].reply->d_func()->connectionChannel = &channels[i]; | - | ||||||||||||||||||
691 | } executed 1125 times by 9 tests: end of block Executed by:
| 1125 | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | QHttpNetworkRequest QHttpNetworkConnectionPrivate::predictNextRequest() | - | ||||||||||||||||||
694 | { | - | ||||||||||||||||||
695 | if (!highPriorityQueue.isEmpty())
| 0-21 | ||||||||||||||||||
696 | return highPriorityQueue.last().first; never executed: return highPriorityQueue.last().first; | 0 | ||||||||||||||||||
697 | if (!lowPriorityQueue.isEmpty())
| 4-17 | ||||||||||||||||||
698 | return lowPriorityQueue.last().first; executed 17 times by 1 test: return lowPriorityQueue.last().first; Executed by:
| 17 | ||||||||||||||||||
699 | return QHttpNetworkRequest(); executed 4 times by 1 test: return QHttpNetworkRequest(); Executed by:
| 4 | ||||||||||||||||||
700 | } | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | // this is called from _q_startNextRequest and when a request has been sent down a socket from the channel | - | ||||||||||||||||||
703 | void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) | - | ||||||||||||||||||
704 | { | - | ||||||||||||||||||
705 | // return fast if there is nothing to pipeline | - | ||||||||||||||||||
706 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 36-3941 | ||||||||||||||||||
707 | return; executed 36 times by 2 tests: return; Executed by:
| 36 | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | int i = indexOf(socket); | - | ||||||||||||||||||
710 | - | |||||||||||||||||||
711 | // return fast if there was no reply right now processed | - | ||||||||||||||||||
712 | if (channels[i].reply == 0)
| 36-4234 | ||||||||||||||||||
713 | return; executed 36 times by 1 test: return; Executed by:
| 36 | ||||||||||||||||||
714 | - | |||||||||||||||||||
715 | if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) {
| 1049-3185 | ||||||||||||||||||
716 | return; executed 1049 times by 2 tests: return; Executed by:
| 1049 | ||||||||||||||||||
717 | } | - | ||||||||||||||||||
718 | - | |||||||||||||||||||
719 | if (channels[i].pipeliningSupported != QHttpNetworkConnectionChannel::PipeliningProbablySupported)
| 298-2887 | ||||||||||||||||||
720 | return; executed 298 times by 2 tests: return; Executed by:
| 298 | ||||||||||||||||||
721 | - | |||||||||||||||||||
722 | // the current request that is in must already support pipelining | - | ||||||||||||||||||
723 | if (!channels[i].request.isPipeliningAllowed())
| 275-2612 | ||||||||||||||||||
724 | return; executed 2612 times by 2 tests: return; Executed by:
| 2612 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | // the current request must be a idempotent (right now we only check GET) | - | ||||||||||||||||||
727 | if (channels[i].request.operation() != QHttpNetworkRequest::Get)
| 65-210 | ||||||||||||||||||
728 | return; executed 65 times by 1 test: return; Executed by:
| 65 | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | // check if socket is connected | - | ||||||||||||||||||
731 | if (socket->state() != QAbstractSocket::ConnectedState)
| 0-210 | ||||||||||||||||||
732 | return; never executed: return; | 0 | ||||||||||||||||||
733 | - | |||||||||||||||||||
734 | // check for resendCurrent | - | ||||||||||||||||||
735 | if (channels[i].resendCurrent)
| 0-210 | ||||||||||||||||||
736 | return; never executed: return; | 0 | ||||||||||||||||||
737 | - | |||||||||||||||||||
738 | // we do not like authentication stuff | - | ||||||||||||||||||
739 | // ### make sure to be OK with this in later releases | - | ||||||||||||||||||
740 | if (!channels[i].authenticator.isNull()
| 0-210 | ||||||||||||||||||
741 | && (!channels[i].authenticator.user().isEmpty()
| 0-210 | ||||||||||||||||||
742 | || !channels[i].authenticator.password().isEmpty()))
| 0-210 | ||||||||||||||||||
743 | return; never executed: return; | 0 | ||||||||||||||||||
744 | if (!channels[i].proxyAuthenticator.isNull()
| 0-210 | ||||||||||||||||||
745 | && (!channels[i].proxyAuthenticator.user().isEmpty()
| 0-210 | ||||||||||||||||||
746 | || !channels[i].proxyAuthenticator.password().isEmpty()))
| 0-210 | ||||||||||||||||||
747 | return; never executed: return; | 0 | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | // must be in ReadingState or WaitingState | - | ||||||||||||||||||
750 | if (! (channels[i].state == QHttpNetworkConnectionChannel::WaitingState
| 15-195 | ||||||||||||||||||
751 | || channels[i].state == QHttpNetworkConnectionChannel::ReadingState))
| 0-195 | ||||||||||||||||||
752 | return; never executed: return; | 0 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | int lengthBefore; | - | ||||||||||||||||||
755 | while (!highPriorityQueue.isEmpty()) {
| 62-180 | ||||||||||||||||||
756 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||
757 | fillPipeline(highPriorityQueue, channels[i]); | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) {
| 30-32 | ||||||||||||||||||
760 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
761 | return; executed 30 times by 1 test: return; Executed by:
| 30 | ||||||||||||||||||
762 | } | - | ||||||||||||||||||
763 | - | |||||||||||||||||||
764 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length())
| 0-32 | ||||||||||||||||||
765 | break; // did not process anything, now do the low prio queue never executed: break; | 0 | ||||||||||||||||||
766 | } executed 32 times by 1 test: end of block Executed by:
| 32 | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | while (!lowPriorityQueue.isEmpty()) {
| 2-355 | ||||||||||||||||||
769 | lengthBefore = channels[i].alreadyPipelinedRequests.length(); | - | ||||||||||||||||||
770 | fillPipeline(lowPriorityQueue, channels[i]); | - | ||||||||||||||||||
771 | - | |||||||||||||||||||
772 | if (channels[i].alreadyPipelinedRequests.length() >= defaultPipelineLength) {
| 162-193 | ||||||||||||||||||
773 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
774 | return; executed 162 times by 2 tests: return; Executed by:
| 162 | ||||||||||||||||||
775 | } | - | ||||||||||||||||||
776 | - | |||||||||||||||||||
777 | if (lengthBefore == channels[i].alreadyPipelinedRequests.length())
| 16-177 | ||||||||||||||||||
778 | break; // did not process anything executed 16 times by 1 test: break; Executed by:
| 16 | ||||||||||||||||||
779 | } executed 177 times by 2 tests: end of block Executed by:
| 177 | ||||||||||||||||||
780 | - | |||||||||||||||||||
781 | - | |||||||||||||||||||
782 | channels[i].pipelineFlush(); | - | ||||||||||||||||||
783 | } executed 18 times by 1 test: end of block Executed by:
| 18 | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | // returns true when the processing of a queue has been done | - | ||||||||||||||||||
786 | bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel) | - | ||||||||||||||||||
787 | { | - | ||||||||||||||||||
788 | if (queue.isEmpty())
| 0-417 | ||||||||||||||||||
789 | return true; never executed: return true; | 0 | ||||||||||||||||||
790 | - | |||||||||||||||||||
791 | for (int i = queue.count() - 1; i >= 0; --i) {
| 16-935 | ||||||||||||||||||
792 | HttpMessagePair messagePair = queue.at(i); | - | ||||||||||||||||||
793 | const QHttpNetworkRequest &request = messagePair.first; | - | ||||||||||||||||||
794 | - | |||||||||||||||||||
795 | // we currently do not support pipelining if HTTP authentication is used | - | ||||||||||||||||||
796 | if (!request.url().userInfo().isEmpty())
| 0-935 | ||||||||||||||||||
797 | continue; never executed: continue; | 0 | ||||||||||||||||||
798 | - | |||||||||||||||||||
799 | // take only GET requests | - | ||||||||||||||||||
800 | if (request.operation() != QHttpNetworkRequest::Get)
| 401-534 | ||||||||||||||||||
801 | continue; executed 534 times by 1 test: continue; Executed by:
| 534 | ||||||||||||||||||
802 | - | |||||||||||||||||||
803 | if (!request.isPipeliningAllowed())
| 0-401 | ||||||||||||||||||
804 | continue; never executed: continue; | 0 | ||||||||||||||||||
805 | - | |||||||||||||||||||
806 | // remove it from the queue | - | ||||||||||||||||||
807 | queue.takeAt(i); | - | ||||||||||||||||||
808 | // we modify the queue we iterate over here, but since we return from the function | - | ||||||||||||||||||
809 | // afterwards this is fine. | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | // actually send it | - | ||||||||||||||||||
812 | if (!messagePair.second->d_func()->requestIsPrepared)
| 0-401 | ||||||||||||||||||
813 | prepareRequest(messagePair); executed 401 times by 2 tests: prepareRequest(messagePair); Executed by:
| 401 | ||||||||||||||||||
814 | channel.pipelineInto(messagePair); | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | // return false because we processed something and need to process again | - | ||||||||||||||||||
817 | return false; executed 401 times by 2 tests: return false; Executed by:
| 401 | ||||||||||||||||||
818 | } | - | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | // return true, the queue has been processed and not changed | - | ||||||||||||||||||
821 | return true; executed 16 times by 1 test: return true; Executed by:
| 16 | ||||||||||||||||||
822 | } | - | ||||||||||||||||||
823 | - | |||||||||||||||||||
824 | - | |||||||||||||||||||
825 | QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, const QString &extraDetail) | - | ||||||||||||||||||
826 | { | - | ||||||||||||||||||
827 | QString errorString; | - | ||||||||||||||||||
828 | switch (errorCode) { | - | ||||||||||||||||||
829 | case QNetworkReply::HostNotFoundError: executed 6 times by 3 tests: case QNetworkReply::HostNotFoundError: Executed by:
| 6 | ||||||||||||||||||
830 | if (socket)
| 2-4 | ||||||||||||||||||
831 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName()); executed 2 times by 1 test: errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName()); Executed by:
| 2 | ||||||||||||||||||
832 | else | - | ||||||||||||||||||
833 | errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName); executed 4 times by 3 tests: errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName); Executed by:
| 4 | ||||||||||||||||||
834 | break; executed 6 times by 3 tests: break; Executed by:
| 6 | ||||||||||||||||||
835 | case QNetworkReply::ConnectionRefusedError: executed 124 times by 2 tests: case QNetworkReply::ConnectionRefusedError: Executed by:
| 124 | ||||||||||||||||||
836 | errorString = QCoreApplication::translate("QHttp", "Connection refused"); | - | ||||||||||||||||||
837 | break; executed 124 times by 2 tests: break; Executed by:
| 124 | ||||||||||||||||||
838 | case QNetworkReply::RemoteHostClosedError: executed 35 times by 3 tests: case QNetworkReply::RemoteHostClosedError: Executed by:
| 35 | ||||||||||||||||||
839 | errorString = QCoreApplication::translate("QHttp", "Connection closed"); | - | ||||||||||||||||||
840 | break; executed 35 times by 3 tests: break; Executed by:
| 35 | ||||||||||||||||||
841 | case QNetworkReply::TimeoutError: never executed: case QNetworkReply::TimeoutError: | 0 | ||||||||||||||||||
842 | errorString = QCoreApplication::translate("QAbstractSocket", "Socket operation timed out"); | - | ||||||||||||||||||
843 | break; never executed: break; | 0 | ||||||||||||||||||
844 | case QNetworkReply::ProxyAuthenticationRequiredError: executed 9 times by 2 tests: case QNetworkReply::ProxyAuthenticationRequiredError: Executed by:
| 9 | ||||||||||||||||||
845 | errorString = QCoreApplication::translate("QHttp", "Proxy requires authentication"); | - | ||||||||||||||||||
846 | break; executed 9 times by 2 tests: break; Executed by:
| 9 | ||||||||||||||||||
847 | case QNetworkReply::AuthenticationRequiredError: executed 37 times by 2 tests: case QNetworkReply::AuthenticationRequiredError: Executed by:
| 37 | ||||||||||||||||||
848 | errorString = QCoreApplication::translate("QHttp", "Host requires authentication"); | - | ||||||||||||||||||
849 | break; executed 37 times by 2 tests: break; Executed by:
| 37 | ||||||||||||||||||
850 | case QNetworkReply::ProtocolFailure: executed 1 time by 1 test: case QNetworkReply::ProtocolFailure: Executed by:
| 1 | ||||||||||||||||||
851 | errorString = QCoreApplication::translate("QHttp", "Data corrupted"); | - | ||||||||||||||||||
852 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
853 | case QNetworkReply::ProtocolUnknownError: never executed: case QNetworkReply::ProtocolUnknownError: | 0 | ||||||||||||||||||
854 | errorString = QCoreApplication::translate("QHttp", "Unknown protocol specified"); | - | ||||||||||||||||||
855 | break; never executed: break; | 0 | ||||||||||||||||||
856 | case QNetworkReply::SslHandshakeFailedError: executed 12 times by 3 tests: case QNetworkReply::SslHandshakeFailedError: Executed by:
| 12 | ||||||||||||||||||
857 | errorString = QCoreApplication::translate("QHttp", "SSL handshake failed"); | - | ||||||||||||||||||
858 | break; executed 12 times by 3 tests: break; Executed by:
| 12 | ||||||||||||||||||
859 | case QNetworkReply::TooManyRedirectsError: executed 1 time by 1 test: case QNetworkReply::TooManyRedirectsError: Executed by:
| 1 | ||||||||||||||||||
860 | errorString = QCoreApplication::translate("QHttp", "Too many redirects"); | - | ||||||||||||||||||
861 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
862 | case QNetworkReply::InsecureRedirectError: never executed: case QNetworkReply::InsecureRedirectError: | 0 | ||||||||||||||||||
863 | errorString = QCoreApplication::translate("QHttp", "Insecure redirect"); | - | ||||||||||||||||||
864 | break; never executed: break; | 0 | ||||||||||||||||||
865 | default: executed 4 times by 2 tests: default: Executed by:
| 4 | ||||||||||||||||||
866 | // all other errors are treated as QNetworkReply::UnknownNetworkError | - | ||||||||||||||||||
867 | errorString = extraDetail; | - | ||||||||||||||||||
868 | break; executed 4 times by 2 tests: break; Executed by:
| 4 | ||||||||||||||||||
869 | } | - | ||||||||||||||||||
870 | return errorString; executed 229 times by 4 tests: return errorString; Executed by:
| 229 | ||||||||||||||||||
871 | } | - | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | // this is called from the destructor of QHttpNetworkReply. It is called when | - | ||||||||||||||||||
874 | // the reply was finished correctly or when it was aborted. | - | ||||||||||||||||||
875 | void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) | - | ||||||||||||||||||
876 | { | - | ||||||||||||||||||
877 | Q_Q(QHttpNetworkConnection); | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | // check if the reply is currently being processed or it is pipelined in | - | ||||||||||||||||||
880 | for (int i = 0; i < channelCount; ++i) {
| 1538-6240 | ||||||||||||||||||
881 | // is the reply associated the currently processing of this channel? | - | ||||||||||||||||||
882 | if (channels[i].reply == reply) {
| 26-6214 | ||||||||||||||||||
883 | channels[i].reply = 0; | - | ||||||||||||||||||
884 | if (channels[i].protocolHandler)
| 0-26 | ||||||||||||||||||
885 | channels[i].protocolHandler->setReply(0); executed 26 times by 4 tests: channels[i].protocolHandler->setReply(0); Executed by:
| 26 | ||||||||||||||||||
886 | channels[i].request = QHttpNetworkRequest(); | - | ||||||||||||||||||
887 | channels[i].resendCurrent = false; | - | ||||||||||||||||||
888 | - | |||||||||||||||||||
889 | if (!reply->isFinished() && !channels[i].alreadyPipelinedRequests.isEmpty()) {
| 0-20 | ||||||||||||||||||
890 | // the reply had to be prematurely removed, e.g. it was not finished | - | ||||||||||||||||||
891 | // therefore we have to requeue the already pipelined requests. | - | ||||||||||||||||||
892 | channels[i].requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
893 | } never executed: end of block | 0 | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | // if HTTP mandates we should close | - | ||||||||||||||||||
896 | // or the reply is not finished yet, e.g. it was aborted | - | ||||||||||||||||||
897 | // we have to close that connection | - | ||||||||||||||||||
898 | if (reply->d_func()->isConnectionCloseEnabled() || !reply->isFinished()) {
| 0-21 | ||||||||||||||||||
899 | if (reply->isAborted()) {
| 13 | ||||||||||||||||||
900 | channels[i].abort(); | - | ||||||||||||||||||
901 | } else { executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
902 | channels[i].close(); | - | ||||||||||||||||||
903 | } executed 13 times by 4 tests: end of block Executed by:
| 13 | ||||||||||||||||||
904 | } | - | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
907 | return; executed 26 times by 4 tests: return; Executed by:
| 26 | ||||||||||||||||||
908 | } | - | ||||||||||||||||||
909 | - | |||||||||||||||||||
910 | // is the reply inside the pipeline of this channel already? | - | ||||||||||||||||||
911 | for (int j = 0; j < channels[i].alreadyPipelinedRequests.length(); j++) {
| 99-6214 | ||||||||||||||||||
912 | if (channels[i].alreadyPipelinedRequests.at(j).second == reply) {
| 0-99 | ||||||||||||||||||
913 | // Remove that HttpMessagePair | - | ||||||||||||||||||
914 | channels[i].alreadyPipelinedRequests.removeAt(j); | - | ||||||||||||||||||
915 | - | |||||||||||||||||||
916 | channels[i].requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | // Since some requests had already been pipelined, but we removed | - | ||||||||||||||||||
919 | // one and re-queued the others | - | ||||||||||||||||||
920 | // we must force a connection close after the request that is | - | ||||||||||||||||||
921 | // currently in processing has been finished. | - | ||||||||||||||||||
922 | if (channels[i].reply)
| 0 | ||||||||||||||||||
923 | channels[i].reply->d_func()->forceConnectionCloseEnabled = true; never executed: channels[i].reply->d_func()->forceConnectionCloseEnabled = true; | 0 | ||||||||||||||||||
924 | - | |||||||||||||||||||
925 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
926 | return; never executed: return; | 0 | ||||||||||||||||||
927 | } | - | ||||||||||||||||||
928 | } executed 99 times by 1 test: end of block Executed by:
| 99 | ||||||||||||||||||
929 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
930 | // is the reply inside the SPDY pipeline of this channel already? | - | ||||||||||||||||||
931 | QMultiMap<int, HttpMessagePair>::iterator it = channels[i].spdyRequestsToSend.begin(); | - | ||||||||||||||||||
932 | QMultiMap<int, HttpMessagePair>::iterator end = channels[i].spdyRequestsToSend.end(); | - | ||||||||||||||||||
933 | for (; it != end; ++it) {
| 5-6209 | ||||||||||||||||||
934 | if (it.value().second == reply) {
| 0-5 | ||||||||||||||||||
935 | channels[i].spdyRequestsToSend.remove(it.key()); | - | ||||||||||||||||||
936 | - | |||||||||||||||||||
937 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
938 | return; executed 5 times by 1 test: return; Executed by:
| 5 | ||||||||||||||||||
939 | } | - | ||||||||||||||||||
940 | } never executed: end of block | 0 | ||||||||||||||||||
941 | #endif | - | ||||||||||||||||||
942 | } executed 6209 times by 8 tests: end of block Executed by:
| 6209 | ||||||||||||||||||
943 | // remove from the high priority queue | - | ||||||||||||||||||
944 | if (!highPriorityQueue.isEmpty()) {
| 0-1538 | ||||||||||||||||||
945 | for (int j = highPriorityQueue.count() - 1; j >= 0; --j) {
| 0 | ||||||||||||||||||
946 | HttpMessagePair messagePair = highPriorityQueue.at(j); | - | ||||||||||||||||||
947 | if (messagePair.second == reply) {
| 0 | ||||||||||||||||||
948 | highPriorityQueue.removeAt(j); | - | ||||||||||||||||||
949 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
950 | return; never executed: return; | 0 | ||||||||||||||||||
951 | } | - | ||||||||||||||||||
952 | } never executed: end of block | 0 | ||||||||||||||||||
953 | } never executed: end of block | 0 | ||||||||||||||||||
954 | // remove from the low priority queue | - | ||||||||||||||||||
955 | if (!lowPriorityQueue.isEmpty()) {
| 96-1442 | ||||||||||||||||||
956 | for (int j = lowPriorityQueue.count() - 1; j >= 0; --j) {
| 88-524 | ||||||||||||||||||
957 | HttpMessagePair messagePair = lowPriorityQueue.at(j); | - | ||||||||||||||||||
958 | if (messagePair.second == reply) {
| 8-516 | ||||||||||||||||||
959 | lowPriorityQueue.removeAt(j); | - | ||||||||||||||||||
960 | QMetaObject::invokeMethod(q, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
961 | return; executed 8 times by 2 tests: return; Executed by:
| 8 | ||||||||||||||||||
962 | } | - | ||||||||||||||||||
963 | } executed 516 times by 2 tests: end of block Executed by:
| 516 | ||||||||||||||||||
964 | } executed 88 times by 2 tests: end of block Executed by:
| 88 | ||||||||||||||||||
965 | } executed 1530 times by 7 tests: end of block Executed by:
| 1530 | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | - | |||||||||||||||||||
968 | - | |||||||||||||||||||
969 | // This function must be called from the event loop. The only | - | ||||||||||||||||||
970 | // exception is documented in QHttpNetworkConnectionPrivate::queueRequest | - | ||||||||||||||||||
971 | // although it is called _q_startNextRequest, it will actually start multiple requests when possible | - | ||||||||||||||||||
972 | void QHttpNetworkConnectionPrivate::_q_startNextRequest() | - | ||||||||||||||||||
973 | { | - | ||||||||||||||||||
974 | // If there is no network layer state decided we should not start any new requests. | - | ||||||||||||||||||
975 | if (networkLayerState == Unknown || networkLayerState == HostLookupPending || networkLayerState == IPv4or6)
| 0-5353 | ||||||||||||||||||
976 | return; executed 4 times by 3 tests: return; Executed by:
| 4 | ||||||||||||||||||
977 | - | |||||||||||||||||||
978 | // If the QHttpNetworkConnection is currently paused then bail out immediately | - | ||||||||||||||||||
979 | if (state == PausedState)
| 0-5351 | ||||||||||||||||||
980 | return; never executed: return; | 0 | ||||||||||||||||||
981 | - | |||||||||||||||||||
982 | //resend the necessary ones. | - | ||||||||||||||||||
983 | for (int i = 0; i < channelCount; ++i) {
| 5351-25421 | ||||||||||||||||||
984 | if (channels[i].resendCurrent && (channels[i].state != QHttpNetworkConnectionChannel::ClosingState)) {
| 0-25179 | ||||||||||||||||||
985 | channels[i].resendCurrent = false; | - | ||||||||||||||||||
986 | - | |||||||||||||||||||
987 | // if this is not possible, error will be emitted and connection terminated | - | ||||||||||||||||||
988 | if (!channels[i].resetUploadData())
| 9-233 | ||||||||||||||||||
989 | continue; executed 9 times by 2 tests: continue; Executed by:
| 9 | ||||||||||||||||||
990 | channels[i].sendRequest(); | - | ||||||||||||||||||
991 | } executed 233 times by 3 tests: end of block Executed by:
| 233 | ||||||||||||||||||
992 | } executed 25412 times by 9 tests: end of block Executed by:
| 25412 | ||||||||||||||||||
993 | - | |||||||||||||||||||
994 | // dequeue new ones | - | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | switch (connectionType) { | - | ||||||||||||||||||
997 | case QHttpNetworkConnection::ConnectionTypeHTTP: { executed 5226 times by 9 tests: case QHttpNetworkConnection::ConnectionTypeHTTP: Executed by:
| 5226 | ||||||||||||||||||
998 | // return fast if there is nothing to do | - | ||||||||||||||||||
999 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 355-4871 | ||||||||||||||||||
1000 | return; executed 2557 times by 8 tests: return; Executed by:
| 2557 | ||||||||||||||||||
1001 | - | |||||||||||||||||||
1002 | // try to get a free AND connected socket | - | ||||||||||||||||||
1003 | for (int i = 0; i < channelCount; ++i) {
| 2669-10087 | ||||||||||||||||||
1004 | if (channels[i].socket) {
| 3638-6449 | ||||||||||||||||||
1005 | if (!channels[i].reply && !channels[i].isSocketBusy() && channels[i].socket->state() == QAbstractSocket::ConnectedState) {
| 56-3613 | ||||||||||||||||||
1006 | if (dequeueRequest(channels[i].socket))
| 15-464 | ||||||||||||||||||
1007 | channels[i].sendRequest(); executed 464 times by 4 tests: channels[i].sendRequest(); Executed by:
| 464 | ||||||||||||||||||
1008 | } executed 479 times by 4 tests: end of block Executed by:
| 479 | ||||||||||||||||||
1009 | } executed 6449 times by 4 tests: end of block Executed by:
| 6449 | ||||||||||||||||||
1010 | } executed 10087 times by 7 tests: end of block Executed by:
| 10087 | ||||||||||||||||||
1011 | break; executed 2669 times by 7 tests: break; Executed by:
| 2669 | ||||||||||||||||||
1012 | } | - | ||||||||||||||||||
1013 | case QHttpNetworkConnection::ConnectionTypeSPDY: { executed 125 times by 1 test: case QHttpNetworkConnection::ConnectionTypeSPDY: Executed by:
| 125 | ||||||||||||||||||
1014 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1015 | if (channels[0].spdyRequestsToSend.isEmpty())
| 6-119 | ||||||||||||||||||
1016 | return; executed 6 times by 1 test: return; Executed by:
| 6 | ||||||||||||||||||
1017 | - | |||||||||||||||||||
1018 | if (networkLayerState == IPv4)
| 0-119 | ||||||||||||||||||
1019 | channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; executed 119 times by 1 test: channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; Executed by:
| 119 | ||||||||||||||||||
1020 | else if (networkLayerState == IPv6)
| 0 | ||||||||||||||||||
1021 | channels[0].networkLayerPreference = QAbstractSocket::IPv6Protocol; never executed: channels[0].networkLayerPreference = QAbstractSocket::IPv6Protocol; | 0 | ||||||||||||||||||
1022 | channels[0].ensureConnection(); | - | ||||||||||||||||||
1023 | if (channels[0].socket && channels[0].socket->state() == QAbstractSocket::ConnectedState
| 0-119 | ||||||||||||||||||
1024 | && !channels[0].pendingEncrypt)
| 0-107 | ||||||||||||||||||
1025 | channels[0].sendRequest(); executed 107 times by 1 test: channels[0].sendRequest(); Executed by:
| 107 | ||||||||||||||||||
1026 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1027 | break; executed 119 times by 1 test: break; Executed by:
| 119 | ||||||||||||||||||
1028 | } | - | ||||||||||||||||||
1029 | } | - | ||||||||||||||||||
1030 | - | |||||||||||||||||||
1031 | // try to push more into all sockets | - | ||||||||||||||||||
1032 | // ### FIXME we should move this to the beginning of the function | - | ||||||||||||||||||
1033 | // as soon as QtWebkit is properly using the pipelining | - | ||||||||||||||||||
1034 | // (e.g. not for XMLHttpRequest or the first page load) | - | ||||||||||||||||||
1035 | // ### FIXME we should also divide the requests more even | - | ||||||||||||||||||
1036 | // on the connected sockets | - | ||||||||||||||||||
1037 | //tryToFillPipeline(socket); | - | ||||||||||||||||||
1038 | // return fast if there is nothing to pipeline | - | ||||||||||||||||||
1039 | if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
| 194-2434 | ||||||||||||||||||
1040 | return; executed 194 times by 4 tests: return; Executed by:
| 194 | ||||||||||||||||||
1041 | for (int i = 0; i < channelCount; i++)
| 2594-9650 | ||||||||||||||||||
1042 | if (channels[i].socket && channels[i].socket->state() == QAbstractSocket::ConnectedState)
| 2414-6319 | ||||||||||||||||||
1043 | fillPipeline(channels[i].socket); executed 3905 times by 2 tests: fillPipeline(channels[i].socket); Executed by:
| 3905 | ||||||||||||||||||
1044 | - | |||||||||||||||||||
1045 | // If there is not already any connected channels we need to connect a new one. | - | ||||||||||||||||||
1046 | // We do not pair the channel with the request until we know if it is | - | ||||||||||||||||||
1047 | // connected or not. This is to reuse connected channels before we connect new once. | - | ||||||||||||||||||
1048 | int queuedRequests = highPriorityQueue.count() + lowPriorityQueue.count(); | - | ||||||||||||||||||
1049 | - | |||||||||||||||||||
1050 | // in case we have in-flight preconnect requests and normal requests, | - | ||||||||||||||||||
1051 | // we only need one socket for each (preconnect, normal request) pair | - | ||||||||||||||||||
1052 | int neededOpenChannels = queuedRequests; | - | ||||||||||||||||||
1053 | if (preConnectRequests > 0) {
| 0-2594 | ||||||||||||||||||
1054 | int normalRequests = queuedRequests - preConnectRequests; | - | ||||||||||||||||||
1055 | neededOpenChannels = qMax(normalRequests, preConnectRequests); | - | ||||||||||||||||||
1056 | } never executed: end of block | 0 | ||||||||||||||||||
1057 | for (int i = 0; i < channelCount && neededOpenChannels > 0; ++i) {
| 508-7265 | ||||||||||||||||||
1058 | bool connectChannel = false; | - | ||||||||||||||||||
1059 | if (channels[i].socket) {
| 496-6261 | ||||||||||||||||||
1060 | if ((channels[i].socket->state() == QAbstractSocket::ConnectingState)
| 2332-3929 | ||||||||||||||||||
1061 | || (channels[i].socket->state() == QAbstractSocket::HostLookupState)
| 0-3929 | ||||||||||||||||||
1062 | || channels[i].pendingEncrypt) // pendingEncrypt == "EncryptingState"
| 26-3903 | ||||||||||||||||||
1063 | neededOpenChannels--; executed 2358 times by 2 tests: neededOpenChannels--; Executed by:
| 2358 | ||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | if (neededOpenChannels <= 0)
| 124-6137 | ||||||||||||||||||
1066 | break; executed 124 times by 2 tests: break; Executed by:
| 124 | ||||||||||||||||||
1067 | if (!channels[i].reply && !channels[i].isSocketBusy() && (channels[i].socket->state() == QAbstractSocket::UnconnectedState))
| 0-3929 | ||||||||||||||||||
1068 | connectChannel = true; executed 47 times by 2 tests: connectChannel = true; Executed by:
| 47 | ||||||||||||||||||
1069 | } else { // not previously used channel executed 6137 times by 2 tests: end of block Executed by:
| 6137 | ||||||||||||||||||
1070 | connectChannel = true; | - | ||||||||||||||||||
1071 | } executed 496 times by 7 tests: end of block Executed by:
| 496 | ||||||||||||||||||
1072 | - | |||||||||||||||||||
1073 | if (connectChannel) {
| 543-6090 | ||||||||||||||||||
1074 | if (networkLayerState == IPv4)
| 1-542 | ||||||||||||||||||
1075 | channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol; executed 542 times by 7 tests: channels[i].networkLayerPreference = QAbstractSocket::IPv4Protocol; Executed by:
| 542 | ||||||||||||||||||
1076 | else if (networkLayerState == IPv6)
| 0-1 | ||||||||||||||||||
1077 | channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol; executed 1 time by 1 test: channels[i].networkLayerPreference = QAbstractSocket::IPv6Protocol; Executed by:
| 1 | ||||||||||||||||||
1078 | channels[i].ensureConnection(); | - | ||||||||||||||||||
1079 | neededOpenChannels--; | - | ||||||||||||||||||
1080 | } executed 543 times by 7 tests: end of block Executed by:
| 543 | ||||||||||||||||||
1081 | } executed 6633 times by 7 tests: end of block Executed by:
| 6633 | ||||||||||||||||||
1082 | } executed 2594 times by 7 tests: end of block Executed by:
| 2594 | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | - | |||||||||||||||||||
1085 | void QHttpNetworkConnectionPrivate::readMoreLater(QHttpNetworkReply *reply) | - | ||||||||||||||||||
1086 | { | - | ||||||||||||||||||
1087 | for (int i = 0 ; i < channelCount; ++i) {
| 16-286 | ||||||||||||||||||
1088 | if (channels[i].reply == reply) {
| 96-190 | ||||||||||||||||||
1089 | // emulate a readyRead() from the socket | - | ||||||||||||||||||
1090 | QMetaObject::invokeMethod(&channels[i], "_q_readyRead", Qt::QueuedConnection); | - | ||||||||||||||||||
1091 | return; executed 190 times by 1 test: return; Executed by:
| 190 | ||||||||||||||||||
1092 | } | - | ||||||||||||||||||
1093 | } executed 96 times by 2 tests: end of block Executed by:
| 96 | ||||||||||||||||||
1094 | } executed 16 times by 2 tests: end of block Executed by:
| 16 | ||||||||||||||||||
1095 | - | |||||||||||||||||||
1096 | - | |||||||||||||||||||
1097 | - | |||||||||||||||||||
1098 | // The first time we start the connection is used we do not know if we | - | ||||||||||||||||||
1099 | // should use IPv4 or IPv6. So we start a hostlookup to figure this out. | - | ||||||||||||||||||
1100 | // Later when we do the connection the socket will not need to do another | - | ||||||||||||||||||
1101 | // lookup as then the hostinfo will already be in the cache. | - | ||||||||||||||||||
1102 | void QHttpNetworkConnectionPrivate::startHostInfoLookup() | - | ||||||||||||||||||
1103 | { | - | ||||||||||||||||||
1104 | networkLayerState = HostLookupPending; | - | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | // check if we already now can decide if this is IPv4 or IPv6 | - | ||||||||||||||||||
1107 | QString lookupHost = hostName; | - | ||||||||||||||||||
1108 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
1109 | if (networkProxy.capabilities() & QNetworkProxy::HostNameLookupCapability) {
| 44-539 | ||||||||||||||||||
1110 | lookupHost = networkProxy.hostName(); | - | ||||||||||||||||||
1111 | } else if (channels[0].proxy.capabilities() & QNetworkProxy::HostNameLookupCapability) { executed 44 times by 1 test: end of block Executed by:
| 44-481 | ||||||||||||||||||
1112 | lookupHost = channels[0].proxy.hostName(); | - | ||||||||||||||||||
1113 | } executed 58 times by 2 tests: end of block Executed by:
| 58 | ||||||||||||||||||
1114 | #endif | - | ||||||||||||||||||
1115 | QHostAddress temp; | - | ||||||||||||||||||
1116 | if (temp.setAddress(lookupHost)) {
| 108-475 | ||||||||||||||||||
1117 | if (temp.protocol() == QAbstractSocket::IPv4Protocol) {
| 1-107 | ||||||||||||||||||
1118 | networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
1119 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
1120 | return; executed 107 times by 5 tests: return; Executed by:
| 107 | ||||||||||||||||||
1121 | } else if (temp.protocol() == QAbstractSocket::IPv6Protocol) {
| 0-1 | ||||||||||||||||||
1122 | networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
1123 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
1124 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
1125 | } | - | ||||||||||||||||||
1126 | } else { never executed: end of block | 0 | ||||||||||||||||||
1127 | int hostLookupId; | - | ||||||||||||||||||
1128 | bool immediateResultValid = false; | - | ||||||||||||||||||
1129 | QHostInfo hostInfo = qt_qhostinfo_lookup(lookupHost, | - | ||||||||||||||||||
1130 | this->q_func(), | - | ||||||||||||||||||
1131 | SLOT(_q_hostLookupFinished(QHostInfo)), | - | ||||||||||||||||||
1132 | &immediateResultValid, | - | ||||||||||||||||||
1133 | &hostLookupId); | - | ||||||||||||||||||
1134 | if (immediateResultValid) {
| 15-460 | ||||||||||||||||||
1135 | _q_hostLookupFinished(hostInfo); | - | ||||||||||||||||||
1136 | } executed 460 times by 6 tests: end of block Executed by:
| 460 | ||||||||||||||||||
1137 | } executed 475 times by 7 tests: end of block Executed by:
| 475 | ||||||||||||||||||
1138 | } | - | ||||||||||||||||||
1139 | - | |||||||||||||||||||
1140 | - | |||||||||||||||||||
1141 | void QHttpNetworkConnectionPrivate::_q_hostLookupFinished(QHostInfo info) | - | ||||||||||||||||||
1142 | { | - | ||||||||||||||||||
1143 | bool bIpv4 = false; | - | ||||||||||||||||||
1144 | bool bIpv6 = false; | - | ||||||||||||||||||
1145 | bool foundAddress = false; | - | ||||||||||||||||||
1146 | if (networkLayerState == IPv4 || networkLayerState == IPv6 || networkLayerState == IPv4or6)
| 0-475 | ||||||||||||||||||
1147 | return; never executed: return; | 0 | ||||||||||||||||||
1148 | - | |||||||||||||||||||
1149 | foreach (const QHostAddress &address, info.addresses()) { | - | ||||||||||||||||||
1150 | if (address.protocol() == QAbstractSocket::IPv4Protocol) {
| 130-475 | ||||||||||||||||||
1151 | if (!foundAddress) {
| 126-349 | ||||||||||||||||||
1152 | foundAddress = true; | - | ||||||||||||||||||
1153 | delayIpv4 = false; | - | ||||||||||||||||||
1154 | } executed 349 times by 6 tests: end of block Executed by:
| 349 | ||||||||||||||||||
1155 | bIpv4 = true; | - | ||||||||||||||||||
1156 | } else if (address.protocol() == QAbstractSocket::IPv6Protocol) { executed 475 times by 7 tests: end of block Executed by:
| 0-475 | ||||||||||||||||||
1157 | if (!foundAddress) {
| 8-122 | ||||||||||||||||||
1158 | foundAddress = true; | - | ||||||||||||||||||
1159 | delayIpv4 = true; | - | ||||||||||||||||||
1160 | } executed 122 times by 2 tests: end of block Executed by:
| 122 | ||||||||||||||||||
1161 | bIpv6 = true; | - | ||||||||||||||||||
1162 | } executed 130 times by 3 tests: end of block Executed by:
| 130 | ||||||||||||||||||
1163 | } executed 605 times by 7 tests: end of block Executed by:
| 605 | ||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | if (bIpv4 && bIpv6)
| 4-471 | ||||||||||||||||||
1166 | startNetworkLayerStateLookup(); executed 126 times by 3 tests: startNetworkLayerStateLookup(); Executed by:
| 126 | ||||||||||||||||||
1167 | else if (bIpv4) {
| 4-345 | ||||||||||||||||||
1168 | networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | - | ||||||||||||||||||
1169 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
1170 | } else if (bIpv6) { executed 345 times by 5 tests: end of block Executed by:
| 0-345 | ||||||||||||||||||
1171 | networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | - | ||||||||||||||||||
1172 | QMetaObject::invokeMethod(this->q_func(), "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
1173 | } else { never executed: end of block | 0 | ||||||||||||||||||
1174 | if (dequeueRequest(channels[0].socket)) {
| 2 | ||||||||||||||||||
1175 | emitReplyError(channels[0].socket, channels[0].reply, QNetworkReply::HostNotFoundError); | - | ||||||||||||||||||
1176 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
1177 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||||||||
1178 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1179 | else if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 0-2 | ||||||||||||||||||
1180 | QList<HttpMessagePair> spdyPairs = channels[0].spdyRequestsToSend.values(); | - | ||||||||||||||||||
1181 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 2 | ||||||||||||||||||
1182 | // emit error for all replies | - | ||||||||||||||||||
1183 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
1184 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
1185 | emitReplyError(channels[0].socket, currentReply, QNetworkReply::HostNotFoundError); | - | ||||||||||||||||||
1186 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1187 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
1188 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1189 | else { | - | ||||||||||||||||||
1190 | // Should not happen | - | ||||||||||||||||||
1191 | qWarning() << "QHttpNetworkConnectionPrivate::_q_hostLookupFinished could not dequeu request"; | - | ||||||||||||||||||
1192 | networkLayerState = QHttpNetworkConnectionPrivate::Unknown; | - | ||||||||||||||||||
1193 | } never executed: end of block | 0 | ||||||||||||||||||
1194 | } | - | ||||||||||||||||||
1195 | } | - | ||||||||||||||||||
1196 | - | |||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | // This will be used if the host lookup found both and Ipv4 and | - | ||||||||||||||||||
1199 | // Ipv6 address. Then we will start up two connections and pick | - | ||||||||||||||||||
1200 | // the network layer of the one that finish first. The second | - | ||||||||||||||||||
1201 | // connection will then be disconnected. | - | ||||||||||||||||||
1202 | void QHttpNetworkConnectionPrivate::startNetworkLayerStateLookup() | - | ||||||||||||||||||
1203 | { | - | ||||||||||||||||||
1204 | if (channelCount > 1) {
| 0-126 | ||||||||||||||||||
1205 | // At this time all channels should be unconnected. | - | ||||||||||||||||||
1206 | Q_ASSERT(!channels[0].isSocketBusy()); | - | ||||||||||||||||||
1207 | Q_ASSERT(!channels[1].isSocketBusy()); | - | ||||||||||||||||||
1208 | - | |||||||||||||||||||
1209 | networkLayerState = IPv4or6; | - | ||||||||||||||||||
1210 | - | |||||||||||||||||||
1211 | channels[0].networkLayerPreference = QAbstractSocket::IPv4Protocol; | - | ||||||||||||||||||
1212 | channels[1].networkLayerPreference = QAbstractSocket::IPv6Protocol; | - | ||||||||||||||||||
1213 | - | |||||||||||||||||||
1214 | int timeout = 300; | - | ||||||||||||||||||
1215 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1216 | if (networkSession) {
| 0-126 | ||||||||||||||||||
1217 | if (networkSession->configuration().bearerType() == QNetworkConfiguration::Bearer2G)
| 0-126 | ||||||||||||||||||
1218 | timeout = 800; never executed: timeout = 800; | 0 | ||||||||||||||||||
1219 | else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerCDMA2000)
| 0-126 | ||||||||||||||||||
1220 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||
1221 | else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerWCDMA)
| 0-126 | ||||||||||||||||||
1222 | timeout = 500; never executed: timeout = 500; | 0 | ||||||||||||||||||
1223 | else if (networkSession->configuration().bearerType() == QNetworkConfiguration::BearerHSPA)
| 0-126 | ||||||||||||||||||
1224 | timeout = 400; never executed: timeout = 400; | 0 | ||||||||||||||||||
1225 | } executed 126 times by 3 tests: end of block Executed by:
| 126 | ||||||||||||||||||
1226 | #endif | - | ||||||||||||||||||
1227 | delayedConnectionTimer.start(timeout); | - | ||||||||||||||||||
1228 | if (delayIpv4)
| 4-122 | ||||||||||||||||||
1229 | channels[1].ensureConnection(); executed 122 times by 2 tests: channels[1].ensureConnection(); Executed by:
| 122 | ||||||||||||||||||
1230 | else | - | ||||||||||||||||||
1231 | channels[0].ensureConnection(); executed 4 times by 2 tests: channels[0].ensureConnection(); Executed by:
| 4 | ||||||||||||||||||
1232 | } else { | - | ||||||||||||||||||
1233 | networkLayerState = IPv4or6; | - | ||||||||||||||||||
1234 | channels[0].networkLayerPreference = QAbstractSocket::AnyIPProtocol; | - | ||||||||||||||||||
1235 | channels[0].ensureConnection(); | - | ||||||||||||||||||
1236 | } never executed: end of block | 0 | ||||||||||||||||||
1237 | } | - | ||||||||||||||||||
1238 | - | |||||||||||||||||||
1239 | void QHttpNetworkConnectionPrivate::networkLayerDetected(QAbstractSocket::NetworkLayerProtocol protocol) | - | ||||||||||||||||||
1240 | { | - | ||||||||||||||||||
1241 | for (int i = 0 ; i < channelCount; ++i) {
| 124-744 | ||||||||||||||||||
1242 | if ((channels[i].networkLayerPreference != protocol) && (channels[i].state == QHttpNetworkConnectionChannel::ConnectingState)) {
| 0-620 | ||||||||||||||||||
1243 | channels[i].close(); | - | ||||||||||||||||||
1244 | } never executed: end of block | 0 | ||||||||||||||||||
1245 | } executed 744 times by 2 tests: end of block Executed by:
| 744 | ||||||||||||||||||
1246 | } executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
1247 | - | |||||||||||||||||||
1248 | void QHttpNetworkConnectionPrivate::_q_connectDelayedChannel() | - | ||||||||||||||||||
1249 | { | - | ||||||||||||||||||
1250 | if (delayIpv4)
| 0 | ||||||||||||||||||
1251 | channels[0].ensureConnection(); never executed: channels[0].ensureConnection(); | 0 | ||||||||||||||||||
1252 | else | - | ||||||||||||||||||
1253 | channels[1].ensureConnection(); never executed: channels[1].ensureConnection(); | 0 | ||||||||||||||||||
1254 | } | - | ||||||||||||||||||
1255 | - | |||||||||||||||||||
1256 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1257 | QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||||||||
1258 | QHttpNetworkConnection::ConnectionType connectionType, | - | ||||||||||||||||||
1259 | QObject *parent, QSharedPointer<QNetworkSession> networkSession) | - | ||||||||||||||||||
1260 | : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt, connectionType)), parent) | - | ||||||||||||||||||
1261 | { | - | ||||||||||||||||||
1262 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1263 | d->networkSession = qMove(networkSession); | - | ||||||||||||||||||
1264 | d->init(); | - | ||||||||||||||||||
1265 | } executed 575 times by 8 tests: end of block Executed by:
| 575 | ||||||||||||||||||
1266 | - | |||||||||||||||||||
1267 | QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName, | - | ||||||||||||||||||
1268 | quint16 port, bool encrypt, QObject *parent, | - | ||||||||||||||||||
1269 | QSharedPointer<QNetworkSession> networkSession, | - | ||||||||||||||||||
1270 | QHttpNetworkConnection::ConnectionType connectionType) | - | ||||||||||||||||||
1271 | : QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt, | - | ||||||||||||||||||
1272 | connectionType)), parent) | - | ||||||||||||||||||
1273 | { | - | ||||||||||||||||||
1274 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1275 | d->networkSession = qMove(networkSession); | - | ||||||||||||||||||
1276 | d->init(); | - | ||||||||||||||||||
1277 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
1278 | #else | - | ||||||||||||||||||
1279 | QHttpNetworkConnection::QHttpNetworkConnection(const QString &hostName, quint16 port, bool encrypt, | - | ||||||||||||||||||
1280 | QHttpNetworkConnection::ConnectionType connectionType, QObject *parent) | - | ||||||||||||||||||
1281 | : QObject(*(new QHttpNetworkConnectionPrivate(hostName, port, encrypt , connectionType)), parent) | - | ||||||||||||||||||
1282 | { | - | ||||||||||||||||||
1283 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1284 | d->init(); | - | ||||||||||||||||||
1285 | } | - | ||||||||||||||||||
1286 | - | |||||||||||||||||||
1287 | QHttpNetworkConnection::QHttpNetworkConnection(quint16 connectionCount, const QString &hostName, | - | ||||||||||||||||||
1288 | quint16 port, bool encrypt, QObject *parent, | - | ||||||||||||||||||
1289 | QHttpNetworkConnection::ConnectionType connectionType) | - | ||||||||||||||||||
1290 | : QObject(*(new QHttpNetworkConnectionPrivate(connectionCount, hostName, port, encrypt, | - | ||||||||||||||||||
1291 | connectionType)), parent) | - | ||||||||||||||||||
1292 | { | - | ||||||||||||||||||
1293 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1294 | d->init(); | - | ||||||||||||||||||
1295 | } | - | ||||||||||||||||||
1296 | #endif | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | QHttpNetworkConnection::~QHttpNetworkConnection() | - | ||||||||||||||||||
1299 | { | - | ||||||||||||||||||
1300 | } | - | ||||||||||||||||||
1301 | - | |||||||||||||||||||
1302 | QString QHttpNetworkConnection::hostName() const | - | ||||||||||||||||||
1303 | { | - | ||||||||||||||||||
1304 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
1305 | return d->hostName; executed 22 times by 1 test: return d->hostName; Executed by:
| 22 | ||||||||||||||||||
1306 | } | - | ||||||||||||||||||
1307 | - | |||||||||||||||||||
1308 | quint16 QHttpNetworkConnection::port() const | - | ||||||||||||||||||
1309 | { | - | ||||||||||||||||||
1310 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
1311 | return d->port; executed 22 times by 1 test: return d->port; Executed by:
| 22 | ||||||||||||||||||
1312 | } | - | ||||||||||||||||||
1313 | - | |||||||||||||||||||
1314 | QHttpNetworkReply* QHttpNetworkConnection::sendRequest(const QHttpNetworkRequest &request) | - | ||||||||||||||||||
1315 | { | - | ||||||||||||||||||
1316 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1317 | return d->queueRequest(request); executed 1646 times by 8 tests: return d->queueRequest(request); Executed by:
| 1646 | ||||||||||||||||||
1318 | } | - | ||||||||||||||||||
1319 | - | |||||||||||||||||||
1320 | bool QHttpNetworkConnection::isSsl() const | - | ||||||||||||||||||
1321 | { | - | ||||||||||||||||||
1322 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
1323 | return d->encrypt; executed 22 times by 1 test: return d->encrypt; Executed by:
| 22 | ||||||||||||||||||
1324 | } | - | ||||||||||||||||||
1325 | - | |||||||||||||||||||
1326 | QHttpNetworkConnectionChannel *QHttpNetworkConnection::channels() const | - | ||||||||||||||||||
1327 | { | - | ||||||||||||||||||
1328 | return d_func()->channels; never executed: return d_func()->channels; | 0 | ||||||||||||||||||
1329 | } | - | ||||||||||||||||||
1330 | - | |||||||||||||||||||
1331 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
1332 | void QHttpNetworkConnection::setCacheProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
1333 | { | - | ||||||||||||||||||
1334 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1335 | d->networkProxy = networkProxy; | - | ||||||||||||||||||
1336 | // update the authenticator | - | ||||||||||||||||||
1337 | if (!d->networkProxy.user().isEmpty()) {
| 0-551 | ||||||||||||||||||
1338 | for (int i = 0; i < d->channelCount; ++i) {
| 0 | ||||||||||||||||||
1339 | d->channels[i].proxyAuthenticator.setUser(d->networkProxy.user()); | - | ||||||||||||||||||
1340 | d->channels[i].proxyAuthenticator.setPassword(d->networkProxy.password()); | - | ||||||||||||||||||
1341 | } never executed: end of block | 0 | ||||||||||||||||||
1342 | } never executed: end of block | 0 | ||||||||||||||||||
1343 | } executed 551 times by 8 tests: end of block Executed by:
| 551 | ||||||||||||||||||
1344 | - | |||||||||||||||||||
1345 | QNetworkProxy QHttpNetworkConnection::cacheProxy() const | - | ||||||||||||||||||
1346 | { | - | ||||||||||||||||||
1347 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
1348 | return d->networkProxy; executed 701 times by 9 tests: return d->networkProxy; Executed by:
| 701 | ||||||||||||||||||
1349 | } | - | ||||||||||||||||||
1350 | - | |||||||||||||||||||
1351 | void QHttpNetworkConnection::setTransparentProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
1352 | { | - | ||||||||||||||||||
1353 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1354 | for (int i = 0; i < d->channelCount; ++i)
| 551-3251 | ||||||||||||||||||
1355 | d->channels[i].setProxy(networkProxy); executed 3251 times by 8 tests: d->channels[i].setProxy(networkProxy); Executed by:
| 3251 | ||||||||||||||||||
1356 | } executed 551 times by 8 tests: end of block Executed by:
| 551 | ||||||||||||||||||
1357 | - | |||||||||||||||||||
1358 | QNetworkProxy QHttpNetworkConnection::transparentProxy() const | - | ||||||||||||||||||
1359 | { | - | ||||||||||||||||||
1360 | Q_D(const QHttpNetworkConnection); | - | ||||||||||||||||||
1361 | return d->channels[0].proxy; executed 701 times by 9 tests: return d->channels[0].proxy; Executed by:
| 701 | ||||||||||||||||||
1362 | } | - | ||||||||||||||||||
1363 | #endif | - | ||||||||||||||||||
1364 | - | |||||||||||||||||||
1365 | QHttpNetworkConnection::ConnectionType QHttpNetworkConnection::connectionType() | - | ||||||||||||||||||
1366 | { | - | ||||||||||||||||||
1367 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1368 | return d->connectionType; executed 225 times by 4 tests: return d->connectionType; Executed by:
| 225 | ||||||||||||||||||
1369 | } | - | ||||||||||||||||||
1370 | - | |||||||||||||||||||
1371 | void QHttpNetworkConnection::setConnectionType(ConnectionType type) | - | ||||||||||||||||||
1372 | { | - | ||||||||||||||||||
1373 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1374 | d->connectionType = type; | - | ||||||||||||||||||
1375 | } executed 90 times by 3 tests: end of block Executed by:
| 90 | ||||||||||||||||||
1376 | - | |||||||||||||||||||
1377 | // SSL support below | - | ||||||||||||||||||
1378 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1379 | void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) | - | ||||||||||||||||||
1380 | { | - | ||||||||||||||||||
1381 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1382 | if (!d->encrypt)
| 0-57 | ||||||||||||||||||
1383 | return; never executed: return; | 0 | ||||||||||||||||||
1384 | - | |||||||||||||||||||
1385 | // set the config on all channels | - | ||||||||||||||||||
1386 | for (int i = 0; i < d->channelCount; ++i)
| 57-287 | ||||||||||||||||||
1387 | d->channels[i].setSslConfiguration(config); executed 287 times by 2 tests: d->channels[i].setSslConfiguration(config); Executed by:
| 287 | ||||||||||||||||||
1388 | } executed 57 times by 2 tests: end of block Executed by:
| 57 | ||||||||||||||||||
1389 | - | |||||||||||||||||||
1390 | QSharedPointer<QSslContext> QHttpNetworkConnection::sslContext() | - | ||||||||||||||||||
1391 | { | - | ||||||||||||||||||
1392 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1393 | return d->sslContext; executed 271 times by 3 tests: return d->sslContext; Executed by:
| 271 | ||||||||||||||||||
1394 | } | - | ||||||||||||||||||
1395 | - | |||||||||||||||||||
1396 | void QHttpNetworkConnection::setSslContext(QSharedPointer<QSslContext> context) | - | ||||||||||||||||||
1397 | { | - | ||||||||||||||||||
1398 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1399 | d->sslContext = qMove(context); | - | ||||||||||||||||||
1400 | } executed 95 times by 3 tests: end of block Executed by:
| 95 | ||||||||||||||||||
1401 | - | |||||||||||||||||||
1402 | void QHttpNetworkConnection::ignoreSslErrors(int channel) | - | ||||||||||||||||||
1403 | { | - | ||||||||||||||||||
1404 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1405 | if (!d->encrypt)
| 0-34 | ||||||||||||||||||
1406 | return; never executed: return; | 0 | ||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | if (channel == -1) { // ignore for all channels
| 0-34 | ||||||||||||||||||
1409 | for (int i = 0; i < d->channelCount; ++i) {
| 34-174 | ||||||||||||||||||
1410 | d->channels[i].ignoreSslErrors(); | - | ||||||||||||||||||
1411 | } executed 174 times by 3 tests: end of block Executed by:
| 174 | ||||||||||||||||||
1412 | - | |||||||||||||||||||
1413 | } else { executed 34 times by 3 tests: end of block Executed by:
| 34 | ||||||||||||||||||
1414 | d->channels[channel].ignoreSslErrors(); | - | ||||||||||||||||||
1415 | } never executed: end of block | 0 | ||||||||||||||||||
1416 | } | - | ||||||||||||||||||
1417 | - | |||||||||||||||||||
1418 | void QHttpNetworkConnection::ignoreSslErrors(const QList<QSslError> &errors, int channel) | - | ||||||||||||||||||
1419 | { | - | ||||||||||||||||||
1420 | Q_D(QHttpNetworkConnection); | - | ||||||||||||||||||
1421 | if (!d->encrypt)
| 0-6 | ||||||||||||||||||
1422 | return; never executed: return; | 0 | ||||||||||||||||||
1423 | - | |||||||||||||||||||
1424 | if (channel == -1) { // ignore for all channels
| 0-6 | ||||||||||||||||||
1425 | for (int i = 0; i < d->channelCount; ++i) {
| 6-36 | ||||||||||||||||||
1426 | d->channels[i].ignoreSslErrors(errors); | - | ||||||||||||||||||
1427 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | } else { executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
1430 | d->channels[channel].ignoreSslErrors(errors); | - | ||||||||||||||||||
1431 | } never executed: end of block | 0 | ||||||||||||||||||
1432 | } | - | ||||||||||||||||||
1433 | - | |||||||||||||||||||
1434 | #endif //QT_NO_SSL | - | ||||||||||||||||||
1435 | - | |||||||||||||||||||
1436 | void QHttpNetworkConnection::preConnectFinished() | - | ||||||||||||||||||
1437 | { | - | ||||||||||||||||||
1438 | d_func()->preConnectRequests--; | - | ||||||||||||||||||
1439 | } never executed: end of block | 0 | ||||||||||||||||||
1440 | - | |||||||||||||||||||
1441 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
1442 | // only called from QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired, not | - | ||||||||||||||||||
1443 | // from QHttpNetworkConnectionChannel::handleAuthenticationChallenge | - | ||||||||||||||||||
1444 | // e.g. it is for SOCKS proxies which require authentication. | - | ||||||||||||||||||
1445 | void QHttpNetworkConnectionPrivate::emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth) | - | ||||||||||||||||||
1446 | { | - | ||||||||||||||||||
1447 | // Also pause the connection because socket notifiers may fire while an user | - | ||||||||||||||||||
1448 | // dialog is displaying | - | ||||||||||||||||||
1449 | pauseConnection(); | - | ||||||||||||||||||
1450 | QHttpNetworkReply *reply; | - | ||||||||||||||||||
1451 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1452 | if (connectionType == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-39 | ||||||||||||||||||
1453 | // we choose the reply to emit the proxyAuth signal from somewhat arbitrarily, | - | ||||||||||||||||||
1454 | // but that does not matter because the signal will ultimately be emitted | - | ||||||||||||||||||
1455 | // by the QNetworkAccessManager. | - | ||||||||||||||||||
1456 | Q_ASSERT(chan->spdyRequestsToSend.count() > 0); | - | ||||||||||||||||||
1457 | reply = chan->spdyRequestsToSend.cbegin().value().second; | - | ||||||||||||||||||
1458 | } else { // HTTP executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1459 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1460 | reply = chan->reply; | - | ||||||||||||||||||
1461 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1462 | } executed 39 times by 1 test: end of block Executed by:
| 39 | ||||||||||||||||||
1463 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1464 | - | |||||||||||||||||||
1465 | Q_ASSERT(reply); | - | ||||||||||||||||||
1466 | emit reply->proxyAuthenticationRequired(proxy, auth); | - | ||||||||||||||||||
1467 | resumeConnection(); | - | ||||||||||||||||||
1468 | int i = indexOf(chan->socket); | - | ||||||||||||||||||
1469 | copyCredentials(i, auth, true); | - | ||||||||||||||||||
1470 | } executed 42 times by 2 tests: end of block Executed by:
| 42 | ||||||||||||||||||
1471 | #endif | - | ||||||||||||||||||
1472 | - | |||||||||||||||||||
1473 | - | |||||||||||||||||||
1474 | QT_END_NAMESPACE | - | ||||||||||||||||||
1475 | - | |||||||||||||||||||
1476 | #include "moc_qhttpnetworkconnection_p.cpp" | - | ||||||||||||||||||
1477 | - | |||||||||||||||||||
1478 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |