Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qhttpnetworkconnectionchannel.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Copyright (C) 2014 BlackBerry Limited. All rights reserved. | - | ||||||||||||||||||
5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
6 | ** | - | ||||||||||||||||||
7 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
8 | ** | - | ||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
17 | ** | - | ||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
26 | ** | - | ||||||||||||||||||
27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
30 | ** | - | ||||||||||||||||||
31 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
32 | ** | - | ||||||||||||||||||
33 | ****************************************************************************/ | - | ||||||||||||||||||
34 | - | |||||||||||||||||||
35 | #include "qhttpnetworkconnectionchannel_p.h" | - | ||||||||||||||||||
36 | #include "qhttpnetworkconnection_p.h" | - | ||||||||||||||||||
37 | #include "private/qnoncontiguousbytedevice_p.h" | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | #include <qpair.h> | - | ||||||||||||||||||
40 | #include <qdebug.h> | - | ||||||||||||||||||
41 | - | |||||||||||||||||||
42 | #ifndef QT_NO_HTTP | - | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | #include <private/qhttpprotocolhandler_p.h> | - | ||||||||||||||||||
45 | #include <private/qspdyprotocolhandler_p.h> | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
48 | # include <QtNetwork/qsslkey.h> | - | ||||||||||||||||||
49 | # include <QtNetwork/qsslcipher.h> | - | ||||||||||||||||||
50 | # include <QtNetwork/qsslconfiguration.h> | - | ||||||||||||||||||
51 | #endif | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
54 | #include "private/qnetworksession_p.h" | - | ||||||||||||||||||
55 | #endif | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
58 | - | |||||||||||||||||||
59 | // TODO: Put channel specific stuff here so it does not polute qhttpnetworkconnection.cpp | - | ||||||||||||||||||
60 | - | |||||||||||||||||||
61 | // Because in-flight when sending a request, the server might close our connection (because the persistent HTTP | - | ||||||||||||||||||
62 | // connection times out) | - | ||||||||||||||||||
63 | // We use 3 because we can get a _q_error 3 times depending on the timing: | - | ||||||||||||||||||
64 | static const int reconnectAttemptsDefault = 3; | - | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() | - | ||||||||||||||||||
67 | : socket(0) | - | ||||||||||||||||||
68 | , ssl(false) | - | ||||||||||||||||||
69 | , isInitialized(false) | - | ||||||||||||||||||
70 | , state(IdleState) | - | ||||||||||||||||||
71 | , reply(0) | - | ||||||||||||||||||
72 | , written(0) | - | ||||||||||||||||||
73 | , bytesTotal(0) | - | ||||||||||||||||||
74 | , resendCurrent(false) | - | ||||||||||||||||||
75 | , lastStatus(0) | - | ||||||||||||||||||
76 | , pendingEncrypt(false) | - | ||||||||||||||||||
77 | , reconnectAttempts(reconnectAttemptsDefault) | - | ||||||||||||||||||
78 | , authMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
79 | , proxyAuthMethod(QAuthenticatorPrivate::None) | - | ||||||||||||||||||
80 | , authenticationCredentialsSent(false) | - | ||||||||||||||||||
81 | , proxyCredentialsSent(false) | - | ||||||||||||||||||
82 | , protocolHandler(0) | - | ||||||||||||||||||
83 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
84 | , ignoreAllSslErrors(false) | - | ||||||||||||||||||
85 | #endif | - | ||||||||||||||||||
86 | , pipeliningSupported(PipeliningSupportUnknown) | - | ||||||||||||||||||
87 | , networkLayerPreference(QAbstractSocket::AnyIPProtocol) | - | ||||||||||||||||||
88 | , connection(0) | - | ||||||||||||||||||
89 | { | - | ||||||||||||||||||
90 | // Inlining this function in the header leads to compiler error on | - | ||||||||||||||||||
91 | // release-armv5, on at least timebox 9.2 and 10.1. | - | ||||||||||||||||||
92 | } executed 3416 times by 8 tests: end of block Executed by:
| 3416 | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | void QHttpNetworkConnectionChannel::init() | - | ||||||||||||||||||
95 | { | - | ||||||||||||||||||
96 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
97 | if (connection->d_func()->encrypt)
| 107-646 | ||||||||||||||||||
98 | socket = new QSslSocket; executed 107 times by 3 tests: socket = new QSslSocket; Executed by:
| 107 | ||||||||||||||||||
99 | else | - | ||||||||||||||||||
100 | socket = new QTcpSocket; executed 646 times by 8 tests: socket = new QTcpSocket; Executed by:
| 646 | ||||||||||||||||||
101 | #else | - | ||||||||||||||||||
102 | socket = new QTcpSocket; | - | ||||||||||||||||||
103 | #endif | - | ||||||||||||||||||
104 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
105 | //push session down to socket | - | ||||||||||||||||||
106 | if (networkSession)
| 44-709 | ||||||||||||||||||
107 | socket->setProperty("_q_networksession", QVariant::fromValue(networkSession)); executed 709 times by 8 tests: socket->setProperty("_q_networksession", QVariant::fromValue(networkSession)); Executed by:
| 709 | ||||||||||||||||||
108 | #endif | - | ||||||||||||||||||
109 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
110 | // Set by QNAM anyway, but let's be safe here | - | ||||||||||||||||||
111 | socket->setProxy(QNetworkProxy::NoProxy); | - | ||||||||||||||||||
112 | #endif | - | ||||||||||||||||||
113 | - | |||||||||||||||||||
114 | // After some back and forth in all the last years, this is now a DirectConnection because otherwise | - | ||||||||||||||||||
115 | // the state inside the *Socket classes gets messed up, also in conjunction with the socket notifiers | - | ||||||||||||||||||
116 | // which behave slightly differently on Windows vs Linux | - | ||||||||||||||||||
117 | QObject::connect(socket, SIGNAL(bytesWritten(qint64)), | - | ||||||||||||||||||
118 | this, SLOT(_q_bytesWritten(qint64)), | - | ||||||||||||||||||
119 | Qt::DirectConnection); | - | ||||||||||||||||||
120 | QObject::connect(socket, SIGNAL(connected()), | - | ||||||||||||||||||
121 | this, SLOT(_q_connected()), | - | ||||||||||||||||||
122 | Qt::DirectConnection); | - | ||||||||||||||||||
123 | QObject::connect(socket, SIGNAL(readyRead()), | - | ||||||||||||||||||
124 | this, SLOT(_q_readyRead()), | - | ||||||||||||||||||
125 | Qt::DirectConnection); | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | // The disconnected() and error() signals may already come | - | ||||||||||||||||||
128 | // while calling connectToHost(). | - | ||||||||||||||||||
129 | // In case of a cached hostname or an IP this | - | ||||||||||||||||||
130 | // will then emit a signal to the user of QNetworkReply | - | ||||||||||||||||||
131 | // but cannot be caught because the user did not have a chance yet | - | ||||||||||||||||||
132 | // to connect to QNetworkReply's signals. | - | ||||||||||||||||||
133 | qRegisterMetaType<QAbstractSocket::SocketError>(); | - | ||||||||||||||||||
134 | QObject::connect(socket, SIGNAL(disconnected()), | - | ||||||||||||||||||
135 | this, SLOT(_q_disconnected()), | - | ||||||||||||||||||
136 | Qt::DirectConnection); | - | ||||||||||||||||||
137 | QObject::connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), | - | ||||||||||||||||||
138 | this, SLOT(_q_error(QAbstractSocket::SocketError)), | - | ||||||||||||||||||
139 | Qt::DirectConnection); | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | - | |||||||||||||||||||
142 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
143 | QObject::connect(socket, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
144 | this, SLOT(_q_proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)), | - | ||||||||||||||||||
145 | Qt::DirectConnection); | - | ||||||||||||||||||
146 | #endif | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
149 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
150 | if (sslSocket) {
| 107-646 | ||||||||||||||||||
151 | // won't be a sslSocket if encrypt is false | - | ||||||||||||||||||
152 | QObject::connect(sslSocket, SIGNAL(encrypted()), | - | ||||||||||||||||||
153 | this, SLOT(_q_encrypted()), | - | ||||||||||||||||||
154 | Qt::DirectConnection); | - | ||||||||||||||||||
155 | QObject::connect(sslSocket, SIGNAL(sslErrors(QList<QSslError>)), | - | ||||||||||||||||||
156 | this, SLOT(_q_sslErrors(QList<QSslError>)), | - | ||||||||||||||||||
157 | Qt::DirectConnection); | - | ||||||||||||||||||
158 | QObject::connect(sslSocket, SIGNAL(preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
159 | this, SLOT(_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator*)), | - | ||||||||||||||||||
160 | Qt::DirectConnection); | - | ||||||||||||||||||
161 | QObject::connect(sslSocket, SIGNAL(encryptedBytesWritten(qint64)), | - | ||||||||||||||||||
162 | this, SLOT(_q_encryptedBytesWritten(qint64)), | - | ||||||||||||||||||
163 | Qt::DirectConnection); | - | ||||||||||||||||||
164 | - | |||||||||||||||||||
165 | if (ignoreAllSslErrors)
| 10-97 | ||||||||||||||||||
166 | sslSocket->ignoreSslErrors(); executed 10 times by 2 tests: sslSocket->ignoreSslErrors(); Executed by:
| 10 | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | if (!ignoreSslErrorsList.isEmpty())
| 0-107 | ||||||||||||||||||
169 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); never executed: sslSocket->ignoreSslErrors(ignoreSslErrorsList); | 0 | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | if (!sslConfiguration.isNull())
| 49-58 | ||||||||||||||||||
172 | sslSocket->setSslConfiguration(sslConfiguration); executed 58 times by 2 tests: sslSocket->setSslConfiguration(sslConfiguration); Executed by:
| 58 | ||||||||||||||||||
173 | } else { executed 107 times by 3 tests: end of block Executed by:
| 107 | ||||||||||||||||||
174 | #endif // QT_NO_SSL | - | ||||||||||||||||||
175 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
176 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
177 | } executed 646 times by 8 tests: end of block Executed by:
| 646 | ||||||||||||||||||
178 | #endif | - | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
181 | if (proxy.type() != QNetworkProxy::NoProxy)
| 101-652 | ||||||||||||||||||
182 | socket->setProxy(proxy); executed 101 times by 3 tests: socket->setProxy(proxy); Executed by:
| 101 | ||||||||||||||||||
183 | #endif | - | ||||||||||||||||||
184 | isInitialized = true; | - | ||||||||||||||||||
185 | } executed 753 times by 8 tests: end of block Executed by:
| 753 | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | - | |||||||||||||||||||
188 | void QHttpNetworkConnectionChannel::close() | - | ||||||||||||||||||
189 | { | - | ||||||||||||||||||
190 | if (!socket)
| 4-408 | ||||||||||||||||||
191 | state = QHttpNetworkConnectionChannel::IdleState; executed 4 times by 3 tests: state = QHttpNetworkConnectionChannel::IdleState; Executed by:
| 4 | ||||||||||||||||||
192 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 182-226 | ||||||||||||||||||
193 | state = QHttpNetworkConnectionChannel::IdleState; executed 182 times by 4 tests: state = QHttpNetworkConnectionChannel::IdleState; Executed by:
| 182 | ||||||||||||||||||
194 | else | - | ||||||||||||||||||
195 | state = QHttpNetworkConnectionChannel::ClosingState; executed 226 times by 5 tests: state = QHttpNetworkConnectionChannel::ClosingState; Executed by:
| 226 | ||||||||||||||||||
196 | - | |||||||||||||||||||
197 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
198 | pendingEncrypt = false; | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | if (socket) {
| 4-408 | ||||||||||||||||||
201 | // socket can be 0 since the host lookup is done from qhttpnetworkconnection.cpp while | - | ||||||||||||||||||
202 | // there is no socket yet. | - | ||||||||||||||||||
203 | socket->close(); | - | ||||||||||||||||||
204 | } executed 408 times by 6 tests: end of block Executed by:
| 408 | ||||||||||||||||||
205 | } executed 412 times by 6 tests: end of block Executed by:
| 412 | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | - | |||||||||||||||||||
208 | void QHttpNetworkConnectionChannel::abort() | - | ||||||||||||||||||
209 | { | - | ||||||||||||||||||
210 | if (!socket)
| 0-13 | ||||||||||||||||||
211 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
212 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 0-13 | ||||||||||||||||||
213 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
214 | else | - | ||||||||||||||||||
215 | state = QHttpNetworkConnectionChannel::ClosingState; executed 13 times by 1 test: state = QHttpNetworkConnectionChannel::ClosingState; Executed by:
| 13 | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
218 | pendingEncrypt = false; | - | ||||||||||||||||||
219 | - | |||||||||||||||||||
220 | if (socket) {
| 0-13 | ||||||||||||||||||
221 | // socket can be 0 since the host lookup is done from qhttpnetworkconnection.cpp while | - | ||||||||||||||||||
222 | // there is no socket yet. | - | ||||||||||||||||||
223 | socket->abort(); | - | ||||||||||||||||||
224 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
225 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | - | |||||||||||||||||||
228 | bool QHttpNetworkConnectionChannel::sendRequest() | - | ||||||||||||||||||
229 | { | - | ||||||||||||||||||
230 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
231 | return protocolHandler->sendRequest(); executed 4631 times by 9 tests: return protocolHandler->sendRequest(); Executed by:
| 4631 | ||||||||||||||||||
232 | } | - | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | - | |||||||||||||||||||
235 | void QHttpNetworkConnectionChannel::_q_receiveReply() | - | ||||||||||||||||||
236 | { | - | ||||||||||||||||||
237 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
238 | protocolHandler->_q_receiveReply(); | - | ||||||||||||||||||
239 | } executed 202 times by 3 tests: end of block Executed by:
| 202 | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | void QHttpNetworkConnectionChannel::_q_readyRead() | - | ||||||||||||||||||
242 | { | - | ||||||||||||||||||
243 | Q_ASSERT(!protocolHandler.isNull()); | - | ||||||||||||||||||
244 | protocolHandler->_q_readyRead(); | - | ||||||||||||||||||
245 | } executed 10528 times by 8 tests: end of block Executed by:
| 10528 | ||||||||||||||||||
246 | - | |||||||||||||||||||
247 | // called when unexpectedly reading a -1 or when data is expected but socket is closed | - | ||||||||||||||||||
248 | void QHttpNetworkConnectionChannel::handleUnexpectedEOF() | - | ||||||||||||||||||
249 | { | - | ||||||||||||||||||
250 | Q_ASSERT(reply); | - | ||||||||||||||||||
251 | if (reconnectAttempts <= 0) {
| 27-65 | ||||||||||||||||||
252 | // too many errors reading/receiving/parsing the status, close the socket and emit error | - | ||||||||||||||||||
253 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
254 | close(); | - | ||||||||||||||||||
255 | reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket); | - | ||||||||||||||||||
256 | emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); | - | ||||||||||||||||||
257 | reply = 0; | - | ||||||||||||||||||
258 | if (protocolHandler)
| 0-27 | ||||||||||||||||||
259 | protocolHandler->setReply(0); executed 27 times by 2 tests: protocolHandler->setReply(0); Executed by:
| 27 | ||||||||||||||||||
260 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
261 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
262 | } else { executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||
263 | reconnectAttempts--; | - | ||||||||||||||||||
264 | reply->d_func()->clear(); | - | ||||||||||||||||||
265 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
266 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
267 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
268 | } executed 65 times by 2 tests: end of block Executed by:
| 65 | ||||||||||||||||||
269 | } | - | ||||||||||||||||||
270 | - | |||||||||||||||||||
271 | bool QHttpNetworkConnectionChannel::ensureConnection() | - | ||||||||||||||||||
272 | { | - | ||||||||||||||||||
273 | if (!isInitialized)
| 753-1604 | ||||||||||||||||||
274 | init(); executed 753 times by 8 tests: init(); Executed by:
| 753 | ||||||||||||||||||
275 | - | |||||||||||||||||||
276 | QAbstractSocket::SocketState socketState = socket->state(); | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | // resend this request after we receive the disconnected signal | - | ||||||||||||||||||
279 | // If !socket->isOpen() then we have already called close() on the socket, but there was still a | - | ||||||||||||||||||
280 | // pending connectToHost() for which we hadn't seen a connected() signal, yet. The connected() | - | ||||||||||||||||||
281 | // has now arrived (as indicated by socketState != ClosingState), but we cannot send anything on | - | ||||||||||||||||||
282 | // such a socket anymore. | - | ||||||||||||||||||
283 | if (socketState == QAbstractSocket::ClosingState ||
| 0-2357 | ||||||||||||||||||
284 | (socketState != QAbstractSocket::UnconnectedState && !socket->isOpen())) {
| 0-1435 | ||||||||||||||||||
285 | if (reply)
| 0 | ||||||||||||||||||
286 | resendCurrent = true; never executed: resendCurrent = true; | 0 | ||||||||||||||||||
287 | return false; never executed: return false; | 0 | ||||||||||||||||||
288 | } | - | ||||||||||||||||||
289 | - | |||||||||||||||||||
290 | // already trying to connect? | - | ||||||||||||||||||
291 | if (socketState == QAbstractSocket::HostLookupState ||
| 0-2357 | ||||||||||||||||||
292 | socketState == QAbstractSocket::ConnectingState) {
| 3-2354 | ||||||||||||||||||
293 | return false; executed 3 times by 1 test: return false; Executed by:
| 3 | ||||||||||||||||||
294 | } | - | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | // make sure that this socket is in a connected state, if not initiate | - | ||||||||||||||||||
297 | // connection to the host. | - | ||||||||||||||||||
298 | if (socketState != QAbstractSocket::ConnectedState) {
| 922-1432 | ||||||||||||||||||
299 | // connect to the host if not already connected. | - | ||||||||||||||||||
300 | state = QHttpNetworkConnectionChannel::ConnectingState; | - | ||||||||||||||||||
301 | pendingEncrypt = ssl; | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | // reset state | - | ||||||||||||||||||
304 | pipeliningSupported = PipeliningSupportUnknown; | - | ||||||||||||||||||
305 | authenticationCredentialsSent = false; | - | ||||||||||||||||||
306 | proxyCredentialsSent = false; | - | ||||||||||||||||||
307 | authenticator.detach(); | - | ||||||||||||||||||
308 | QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
309 | priv->hasFailed = false; | - | ||||||||||||||||||
310 | proxyAuthenticator.detach(); | - | ||||||||||||||||||
311 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
312 | priv->hasFailed = false; | - | ||||||||||||||||||
313 | - | |||||||||||||||||||
314 | // This workaround is needed since we use QAuthenticator for NTLM authentication. The "phase == Done" | - | ||||||||||||||||||
315 | // is the usual criteria for emitting authentication signals. The "phase" is set to "Done" when the | - | ||||||||||||||||||
316 | // last header for Authorization is generated by the QAuthenticator. Basic & Digest logic does not | - | ||||||||||||||||||
317 | // check the "phase" for generating the Authorization header. NTLM authentication is a two stage | - | ||||||||||||||||||
318 | // process & needs the "phase". To make sure the QAuthenticator uses the current username/password | - | ||||||||||||||||||
319 | // the phase is reset to Start. | - | ||||||||||||||||||
320 | priv = QAuthenticatorPrivate::getPrivate(authenticator); | - | ||||||||||||||||||
321 | if (priv && priv->phase == QAuthenticatorPrivate::Done)
| 0-922 | ||||||||||||||||||
322 | priv->phase = QAuthenticatorPrivate::Start; never executed: priv->phase = QAuthenticatorPrivate::Start; | 0 | ||||||||||||||||||
323 | priv = QAuthenticatorPrivate::getPrivate(proxyAuthenticator); | - | ||||||||||||||||||
324 | if (priv && priv->phase == QAuthenticatorPrivate::Done)
| 0-922 | ||||||||||||||||||
325 | priv->phase = QAuthenticatorPrivate::Start; never executed: priv->phase = QAuthenticatorPrivate::Start; | 0 | ||||||||||||||||||
326 | - | |||||||||||||||||||
327 | QString connectHost = connection->d_func()->hostName; | - | ||||||||||||||||||
328 | quint16 connectPort = connection->d_func()->port; | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
331 | // HTTPS always use transparent proxy. | - | ||||||||||||||||||
332 | if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !ssl) {
| 0-827 | ||||||||||||||||||
333 | connectHost = connection->d_func()->networkProxy.hostName(); | - | ||||||||||||||||||
334 | connectPort = connection->d_func()->networkProxy.port(); | - | ||||||||||||||||||
335 | } executed 95 times by 1 test: end of block Executed by:
| 95 | ||||||||||||||||||
336 | if (socket->proxy().type() == QNetworkProxy::HttpProxy) {
| 23-899 | ||||||||||||||||||
337 | // Make user-agent field available to HTTP proxy socket engine (QTBUG-17223) | - | ||||||||||||||||||
338 | QByteArray value; | - | ||||||||||||||||||
339 | // ensureConnection is called before any request has been assigned, but can also be called again if reconnecting | - | ||||||||||||||||||
340 | if (request.url().isEmpty())
| 2-21 | ||||||||||||||||||
341 | value = connection->d_func()->predictNextRequest().headerField("user-agent"); executed 21 times by 2 tests: value = connection->d_func()->predictNextRequest().headerField("user-agent"); Executed by:
| 21 | ||||||||||||||||||
342 | else | - | ||||||||||||||||||
343 | value = request.headerField("user-agent"); executed 2 times by 1 test: value = request.headerField("user-agent"); Executed by:
| 2 | ||||||||||||||||||
344 | if (!value.isEmpty()) {
| 6-17 | ||||||||||||||||||
345 | QNetworkProxy proxy(socket->proxy()); | - | ||||||||||||||||||
346 | proxy.setRawHeader("User-Agent", value); //detaches | - | ||||||||||||||||||
347 | socket->setProxy(proxy); | - | ||||||||||||||||||
348 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
349 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||||||||
350 | #endif | - | ||||||||||||||||||
351 | if (ssl) {
| 126-796 | ||||||||||||||||||
352 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
353 | QSslSocket *sslSocket = qobject_cast<QSslSocket*>(socket); | - | ||||||||||||||||||
354 | - | |||||||||||||||||||
355 | // check whether we can re-use an existing SSL session | - | ||||||||||||||||||
356 | // (meaning another socket in this connection has already | - | ||||||||||||||||||
357 | // performed a full handshake) | - | ||||||||||||||||||
358 | if (!connection->sslContext().isNull())
| 25-101 | ||||||||||||||||||
359 | QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext()); executed 25 times by 1 test: QSslSocketPrivate::checkSettingSslContext(sslSocket, connection->sslContext()); Executed by:
| 25 | ||||||||||||||||||
360 | - | |||||||||||||||||||
361 | sslSocket->connectToHostEncrypted(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
362 | if (ignoreAllSslErrors)
| 20-106 | ||||||||||||||||||
363 | sslSocket->ignoreSslErrors(); executed 20 times by 2 tests: sslSocket->ignoreSslErrors(); Executed by:
| 20 | ||||||||||||||||||
364 | sslSocket->ignoreSslErrors(ignoreSslErrorsList); | - | ||||||||||||||||||
365 | - | |||||||||||||||||||
366 | // limit the socket read buffer size. we will read everything into | - | ||||||||||||||||||
367 | // the QHttpNetworkReply anyway, so let's grow only that and not | - | ||||||||||||||||||
368 | // here and there. | - | ||||||||||||||||||
369 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
370 | #else | - | ||||||||||||||||||
371 | // Need to dequeue the request so that we can emit the error. | - | ||||||||||||||||||
372 | if (!reply) | - | ||||||||||||||||||
373 | connection->d_func()->dequeueRequest(socket); | - | ||||||||||||||||||
374 | connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ProtocolUnknownError); | - | ||||||||||||||||||
375 | #endif | - | ||||||||||||||||||
376 | } else { executed 126 times by 3 tests: end of block Executed by:
| 126 | ||||||||||||||||||
377 | // In case of no proxy we can use the Unbuffered QTcpSocket | - | ||||||||||||||||||
378 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
379 | if (connection->d_func()->networkProxy.type() == QNetworkProxy::NoProxy
| 95-701 | ||||||||||||||||||
380 | && connection->cacheProxy().type() == QNetworkProxy::NoProxy
| 0-701 | ||||||||||||||||||
381 | && connection->transparentProxy().type() == QNetworkProxy::NoProxy) {
| 86-615 | ||||||||||||||||||
382 | #endif | - | ||||||||||||||||||
383 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite | QIODevice::Unbuffered, networkLayerPreference); | - | ||||||||||||||||||
384 | // For an Unbuffered QTcpSocket, the read buffer size has a special meaning. | - | ||||||||||||||||||
385 | socket->setReadBufferSize(1*1024); | - | ||||||||||||||||||
386 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
387 | } else { executed 615 times by 9 tests: end of block Executed by:
| 615 | ||||||||||||||||||
388 | socket->connectToHost(connectHost, connectPort, QIODevice::ReadWrite, networkLayerPreference); | - | ||||||||||||||||||
389 | - | |||||||||||||||||||
390 | // limit the socket read buffer size. we will read everything into | - | ||||||||||||||||||
391 | // the QHttpNetworkReply anyway, so let's grow only that and not | - | ||||||||||||||||||
392 | // here and there. | - | ||||||||||||||||||
393 | socket->setReadBufferSize(64*1024); | - | ||||||||||||||||||
394 | } executed 181 times by 2 tests: end of block Executed by:
| 181 | ||||||||||||||||||
395 | #endif | - | ||||||||||||||||||
396 | } | - | ||||||||||||||||||
397 | return false; executed 922 times by 9 tests: return false; Executed by:
| 922 | ||||||||||||||||||
398 | } | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | // This code path for ConnectedState | - | ||||||||||||||||||
401 | if (pendingEncrypt) {
| 0-1432 | ||||||||||||||||||
402 | // Let's only be really connected when we have received the encrypted() signal. Else the state machine seems to mess up | - | ||||||||||||||||||
403 | // and corrupt the things sent to the server. | - | ||||||||||||||||||
404 | return false; never executed: return false; | 0 | ||||||||||||||||||
405 | } | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | return true; executed 1432 times by 9 tests: return true; Executed by:
| 1432 | ||||||||||||||||||
408 | } | - | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | void QHttpNetworkConnectionChannel::allDone() | - | ||||||||||||||||||
411 | { | - | ||||||||||||||||||
412 | Q_ASSERT(reply); | - | ||||||||||||||||||
413 | - | |||||||||||||||||||
414 | if (!reply) {
| 0-1763 | ||||||||||||||||||
415 | qWarning() << "QHttpNetworkConnectionChannel::allDone() called without reply. Please report at http://bugreports.qt.io/"; | - | ||||||||||||||||||
416 | return; never executed: return; | 0 | ||||||||||||||||||
417 | } | - | ||||||||||||||||||
418 | - | |||||||||||||||||||
419 | // while handling 401 & 407, we might reset the status code, so save this. | - | ||||||||||||||||||
420 | bool emitFinished = reply->d_func()->shouldEmitSignals(); | - | ||||||||||||||||||
421 | bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled(); | - | ||||||||||||||||||
422 | detectPipeliningSupport(); | - | ||||||||||||||||||
423 | - | |||||||||||||||||||
424 | handleStatus(); | - | ||||||||||||||||||
425 | // handleStatus() might have removed the reply because it already called connection->emitReplyError() | - | ||||||||||||||||||
426 | - | |||||||||||||||||||
427 | // queue the finished signal, this is required since we might send new requests from | - | ||||||||||||||||||
428 | // slot connected to it. The socket will not fire readyRead signal, if we are already | - | ||||||||||||||||||
429 | // in the slot connected to readyRead | - | ||||||||||||||||||
430 | if (reply && emitFinished)
| 2-1761 | ||||||||||||||||||
431 | QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); executed 1406 times by 8 tests: QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); Executed by:
| 1406 | ||||||||||||||||||
432 | - | |||||||||||||||||||
433 | - | |||||||||||||||||||
434 | // reset the reconnection attempts after we receive a complete reply. | - | ||||||||||||||||||
435 | // in case of failures, each channel will attempt two reconnects before emitting error. | - | ||||||||||||||||||
436 | reconnectAttempts = reconnectAttemptsDefault; | - | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | // now the channel can be seen as free/idle again, all signal emissions for the reply have been done | - | ||||||||||||||||||
439 | if (state != QHttpNetworkConnectionChannel::ClosingState)
| 0-1763 | ||||||||||||||||||
440 | state = QHttpNetworkConnectionChannel::IdleState; executed 1763 times by 8 tests: state = QHttpNetworkConnectionChannel::IdleState; Executed by:
| 1763 | ||||||||||||||||||
441 | - | |||||||||||||||||||
442 | // if it does not need to be sent again we can set it to 0 | - | ||||||||||||||||||
443 | // the previous code did not do that and we had problems with accidental re-sending of a | - | ||||||||||||||||||
444 | // finished request. | - | ||||||||||||||||||
445 | // Note that this may trigger a segfault at some other point. But then we can fix the underlying | - | ||||||||||||||||||
446 | // problem. | - | ||||||||||||||||||
447 | if (!resendCurrent) {
| 326-1437 | ||||||||||||||||||
448 | request = QHttpNetworkRequest(); | - | ||||||||||||||||||
449 | reply = 0; | - | ||||||||||||||||||
450 | protocolHandler->setReply(0); | - | ||||||||||||||||||
451 | } executed 1437 times by 7 tests: end of block Executed by:
| 1437 | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | // move next from pipeline to current request | - | ||||||||||||||||||
454 | if (!alreadyPipelinedRequests.isEmpty()) {
| 401-1362 | ||||||||||||||||||
455 | if (resendCurrent || connectionCloseEnabled || socket->state() != QAbstractSocket::ConnectedState) {
| 0-401 | ||||||||||||||||||
456 | // move the pipelined ones back to the main queue | - | ||||||||||||||||||
457 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
458 | close(); | - | ||||||||||||||||||
459 | } else { never executed: end of block | 0 | ||||||||||||||||||
460 | // there were requests pipelined in and we can continue | - | ||||||||||||||||||
461 | HttpMessagePair messagePair = alreadyPipelinedRequests.takeFirst(); | - | ||||||||||||||||||
462 | - | |||||||||||||||||||
463 | request = messagePair.first; | - | ||||||||||||||||||
464 | reply = messagePair.second; | - | ||||||||||||||||||
465 | protocolHandler->setReply(messagePair.second); | - | ||||||||||||||||||
466 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
467 | resendCurrent = false; | - | ||||||||||||||||||
468 | - | |||||||||||||||||||
469 | written = 0; // message body, excluding the header, irrelevant here | - | ||||||||||||||||||
470 | bytesTotal = 0; // message body total, excluding the header, irrelevant here | - | ||||||||||||||||||
471 | - | |||||||||||||||||||
472 | // pipeline even more | - | ||||||||||||||||||
473 | connection->d_func()->fillPipeline(socket); | - | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | // continue reading | - | ||||||||||||||||||
476 | //_q_receiveReply(); | - | ||||||||||||||||||
477 | // this was wrong, allDone gets called from that function anyway. | - | ||||||||||||||||||
478 | } executed 401 times by 2 tests: end of block Executed by:
| 401 | ||||||||||||||||||
479 | } else if (alreadyPipelinedRequests.isEmpty() && socket->bytesAvailable() > 0) {
| 0-1362 | ||||||||||||||||||
480 | // this is weird. we had nothing pipelined but still bytes available. better close it. | - | ||||||||||||||||||
481 | close(); | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
484 | } else if (alreadyPipelinedRequests.isEmpty()) { never executed: end of block
| 0-1362 | ||||||||||||||||||
485 | if (connectionCloseEnabled)
| 185-1177 | ||||||||||||||||||
486 | if (socket->state() != QAbstractSocket::UnconnectedState)
| 60-125 | ||||||||||||||||||
487 | close(); executed 125 times by 2 tests: close(); Executed by:
| 125 | ||||||||||||||||||
488 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-1362 | ||||||||||||||||||
489 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 1362 times by 8 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 1362 | ||||||||||||||||||
490 | } executed 1362 times by 8 tests: end of block Executed by:
| 1362 | ||||||||||||||||||
491 | } executed 1763 times by 8 tests: end of block Executed by:
| 1763 | ||||||||||||||||||
492 | - | |||||||||||||||||||
493 | void QHttpNetworkConnectionChannel::detectPipeliningSupport() | - | ||||||||||||||||||
494 | { | - | ||||||||||||||||||
495 | Q_ASSERT(reply); | - | ||||||||||||||||||
496 | // detect HTTP Pipelining support | - | ||||||||||||||||||
497 | QByteArray serverHeaderField; | - | ||||||||||||||||||
498 | if ( | - | ||||||||||||||||||
499 | // check for HTTP/1.1 | - | ||||||||||||||||||
500 | (reply->d_func()->majorVersion == 1 && reply->d_func()->minorVersion == 1)
| 0-1763 | ||||||||||||||||||
501 | // check for not having connection close | - | ||||||||||||||||||
502 | && (!reply->d_func()->isConnectionCloseEnabled())
| 4-1518 | ||||||||||||||||||
503 | // check if it is still connected | - | ||||||||||||||||||
504 | && (socket->state() == QAbstractSocket::ConnectedState)
| 11-1507 | ||||||||||||||||||
505 | // check for broken servers in server reply header | - | ||||||||||||||||||
506 | // this is adapted from http://mxr.mozilla.org/firefox/ident?i=SupportsPipelining | - | ||||||||||||||||||
507 | && (serverHeaderField = reply->headerField("Server"), !serverHeaderField.contains("Microsoft-IIS/4."))
| 0-1507 | ||||||||||||||||||
508 | && (!serverHeaderField.contains("Microsoft-IIS/5."))
| 0-1507 | ||||||||||||||||||
509 | && (!serverHeaderField.contains("Netscape-Enterprise/3."))
| 0-1507 | ||||||||||||||||||
510 | // this is adpoted from the knowledge of the Nokia 7.x browser team (DEF143319) | - | ||||||||||||||||||
511 | && (!serverHeaderField.contains("WebLogic"))
| 0-1507 | ||||||||||||||||||
512 | && (!serverHeaderField.startsWith("Rocket")) // a Python Web Server, see Web2py.com
| 0-1507 | ||||||||||||||||||
513 | ) { | - | ||||||||||||||||||
514 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningProbablySupported; | - | ||||||||||||||||||
515 | } else { executed 1507 times by 7 tests: end of block Executed by:
| 1507 | ||||||||||||||||||
516 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
517 | } executed 256 times by 3 tests: end of block Executed by:
| 256 | ||||||||||||||||||
518 | } | - | ||||||||||||||||||
519 | - | |||||||||||||||||||
520 | // called when the connection broke and we need to queue some pipelined requests again | - | ||||||||||||||||||
521 | void QHttpNetworkConnectionChannel::requeueCurrentlyPipelinedRequests() | - | ||||||||||||||||||
522 | { | - | ||||||||||||||||||
523 | for (int i = 0; i < alreadyPipelinedRequests.length(); i++)
| 0-590 | ||||||||||||||||||
524 | connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); never executed: connection->d_func()->requeueRequest(alreadyPipelinedRequests.at(i)); | 0 | ||||||||||||||||||
525 | alreadyPipelinedRequests.clear(); | - | ||||||||||||||||||
526 | - | |||||||||||||||||||
527 | // only run when the QHttpNetworkConnection is not currently being destructed, e.g. | - | ||||||||||||||||||
528 | // this function is called from _q_disconnected which is called because | - | ||||||||||||||||||
529 | // of ~QHttpNetworkConnectionPrivate | - | ||||||||||||||||||
530 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 137-453 | ||||||||||||||||||
531 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 137 times by 4 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 137 | ||||||||||||||||||
532 | } executed 590 times by 9 tests: end of block Executed by:
| 590 | ||||||||||||||||||
533 | - | |||||||||||||||||||
534 | void QHttpNetworkConnectionChannel::handleStatus() | - | ||||||||||||||||||
535 | { | - | ||||||||||||||||||
536 | Q_ASSERT(socket); | - | ||||||||||||||||||
537 | Q_ASSERT(reply); | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | int statusCode = reply->statusCode(); | - | ||||||||||||||||||
540 | bool resend = false; | - | ||||||||||||||||||
541 | - | |||||||||||||||||||
542 | switch (statusCode) { | - | ||||||||||||||||||
543 | case 301: executed 3 times by 1 test: case 301: Executed by:
| 3 | ||||||||||||||||||
544 | case 302: never executed: case 302: | 0 | ||||||||||||||||||
545 | case 303: never executed: case 303: | 0 | ||||||||||||||||||
546 | case 305: never executed: case 305: | 0 | ||||||||||||||||||
547 | case 307: { executed 7 times by 2 tests: case 307: Executed by:
| 7 | ||||||||||||||||||
548 | // Parse the response headers and get the "location" url | - | ||||||||||||||||||
549 | QUrl redirectUrl = connection->d_func()->parseRedirectResponse(socket, reply); | - | ||||||||||||||||||
550 | if (redirectUrl.isValid())
| 4-6 | ||||||||||||||||||
551 | reply->setRedirectUrl(redirectUrl); executed 6 times by 2 tests: reply->setRedirectUrl(redirectUrl); Executed by:
| 6 | ||||||||||||||||||
552 | - | |||||||||||||||||||
553 | if (qobject_cast<QHttpNetworkConnection *>(connection))
| 0-10 | ||||||||||||||||||
554 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 10 times by 3 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 10 | ||||||||||||||||||
555 | break; executed 10 times by 3 tests: break; Executed by:
| 10 | ||||||||||||||||||
556 | } | - | ||||||||||||||||||
557 | case 401: // auth required executed 302 times by 2 tests: case 401: Executed by:
| 302 | ||||||||||||||||||
558 | case 407: // proxy auth required executed 54 times by 1 test: case 407: Executed by:
| 54 | ||||||||||||||||||
559 | if (connection->d_func()->handleAuthenticateChallenge(socket, reply, (statusCode == 407), resend)) {
| 3-353 | ||||||||||||||||||
560 | if (resend) {
| 38-315 | ||||||||||||||||||
561 | if (!resetUploadData())
| 1-314 | ||||||||||||||||||
562 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
563 | - | |||||||||||||||||||
564 | reply->d_func()->eraseData(); | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | if (alreadyPipelinedRequests.isEmpty()) {
| 0-314 | ||||||||||||||||||
567 | // this does a re-send without closing the connection | - | ||||||||||||||||||
568 | resendCurrent = true; | - | ||||||||||||||||||
569 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
570 | } else { executed 314 times by 2 tests: end of block Executed by:
| 314 | ||||||||||||||||||
571 | // we had requests pipelined.. better close the connection in closeAndResendCurrentRequest | - | ||||||||||||||||||
572 | closeAndResendCurrentRequest(); | - | ||||||||||||||||||
573 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
574 | } never executed: end of block | 0 | ||||||||||||||||||
575 | } else { | - | ||||||||||||||||||
576 | //authentication cancelled, close the channel. | - | ||||||||||||||||||
577 | close(); | - | ||||||||||||||||||
578 | } executed 38 times by 2 tests: end of block Executed by:
| 38 | ||||||||||||||||||
579 | } else { | - | ||||||||||||||||||
580 | emit reply->headerChanged(); | - | ||||||||||||||||||
581 | emit reply->readyRead(); | - | ||||||||||||||||||
582 | QNetworkReply::NetworkError errorCode = (statusCode == 407)
| 1-2 | ||||||||||||||||||
583 | ? QNetworkReply::ProxyAuthenticationRequiredError | - | ||||||||||||||||||
584 | : QNetworkReply::AuthenticationRequiredError; | - | ||||||||||||||||||
585 | reply->d_func()->errorString = connection->d_func()->errorDetail(errorCode, socket); | - | ||||||||||||||||||
586 | emit reply->finishedWithError(errorCode, reply->d_func()->errorString); | - | ||||||||||||||||||
587 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
588 | break; executed 355 times by 2 tests: break; Executed by:
| 355 | ||||||||||||||||||
589 | default: executed 1397 times by 6 tests: default: Executed by:
| 1397 | ||||||||||||||||||
590 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-1397 | ||||||||||||||||||
591 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 1397 times by 6 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 1397 | ||||||||||||||||||
592 | } executed 1397 times by 6 tests: end of block Executed by:
| 1397 | ||||||||||||||||||
593 | } | - | ||||||||||||||||||
594 | - | |||||||||||||||||||
595 | bool QHttpNetworkConnectionChannel::resetUploadData() | - | ||||||||||||||||||
596 | { | - | ||||||||||||||||||
597 | if (!reply) {
| 9-548 | ||||||||||||||||||
598 | //this happens if server closes connection while QHttpNetworkConnectionPrivate::_q_startNextRequest is pending | - | ||||||||||||||||||
599 | return false; executed 9 times by 2 tests: return false; Executed by:
| 9 | ||||||||||||||||||
600 | } | - | ||||||||||||||||||
601 | QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice(); | - | ||||||||||||||||||
602 | if (!uploadByteDevice)
| 127-421 | ||||||||||||||||||
603 | return true; executed 421 times by 3 tests: return true; Executed by:
| 421 | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | if (uploadByteDevice->reset()) {
| 1-126 | ||||||||||||||||||
606 | written = 0; | - | ||||||||||||||||||
607 | return true; executed 126 times by 1 test: return true; Executed by:
| 126 | ||||||||||||||||||
608 | } else { | - | ||||||||||||||||||
609 | connection->d_func()->emitReplyError(socket, reply, QNetworkReply::ContentReSendError); | - | ||||||||||||||||||
610 | return false; executed 1 time by 1 test: return false; Executed by:
| 1 | ||||||||||||||||||
611 | } | - | ||||||||||||||||||
612 | } | - | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
615 | - | |||||||||||||||||||
616 | void QHttpNetworkConnectionChannel::setProxy(const QNetworkProxy &networkProxy) | - | ||||||||||||||||||
617 | { | - | ||||||||||||||||||
618 | if (socket)
| 0-3251 | ||||||||||||||||||
619 | socket->setProxy(networkProxy); never executed: socket->setProxy(networkProxy); | 0 | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | proxy = networkProxy; | - | ||||||||||||||||||
622 | } executed 3251 times by 8 tests: end of block Executed by:
| 3251 | ||||||||||||||||||
623 | - | |||||||||||||||||||
624 | #endif | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | void QHttpNetworkConnectionChannel::ignoreSslErrors() | - | ||||||||||||||||||
629 | { | - | ||||||||||||||||||
630 | if (socket)
| 33-141 | ||||||||||||||||||
631 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(); executed 33 times by 3 tests: static_cast<QSslSocket *>(socket)->ignoreSslErrors(); Executed by:
| 33 | ||||||||||||||||||
632 | - | |||||||||||||||||||
633 | ignoreAllSslErrors = true; | - | ||||||||||||||||||
634 | } executed 174 times by 3 tests: end of block Executed by:
| 174 | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | - | |||||||||||||||||||
637 | void QHttpNetworkConnectionChannel::ignoreSslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
638 | { | - | ||||||||||||||||||
639 | if (socket)
| 6-30 | ||||||||||||||||||
640 | static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors); executed 6 times by 1 test: static_cast<QSslSocket *>(socket)->ignoreSslErrors(errors); Executed by:
| 6 | ||||||||||||||||||
641 | - | |||||||||||||||||||
642 | ignoreSslErrorsList = errors; | - | ||||||||||||||||||
643 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
644 | - | |||||||||||||||||||
645 | void QHttpNetworkConnectionChannel::setSslConfiguration(const QSslConfiguration &config) | - | ||||||||||||||||||
646 | { | - | ||||||||||||||||||
647 | if (socket)
| 0-287 | ||||||||||||||||||
648 | static_cast<QSslSocket *>(socket)->setSslConfiguration(config); never executed: static_cast<QSslSocket *>(socket)->setSslConfiguration(config); | 0 | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | sslConfiguration = config; | - | ||||||||||||||||||
651 | } executed 287 times by 2 tests: end of block Executed by:
| 287 | ||||||||||||||||||
652 | - | |||||||||||||||||||
653 | #endif | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) | - | ||||||||||||||||||
656 | { | - | ||||||||||||||||||
657 | // this is only called for simple GET | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | QHttpNetworkRequest &request = pair.first; | - | ||||||||||||||||||
660 | QHttpNetworkReply *reply = pair.second; | - | ||||||||||||||||||
661 | reply->d_func()->clear(); | - | ||||||||||||||||||
662 | reply->d_func()->connection = connection; | - | ||||||||||||||||||
663 | reply->d_func()->connectionChannel = this; | - | ||||||||||||||||||
664 | reply->d_func()->autoDecompress = request.d->autoDecompress; | - | ||||||||||||||||||
665 | reply->d_func()->pipeliningUsed = true; | - | ||||||||||||||||||
666 | - | |||||||||||||||||||
667 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
668 | pipeline.append(QHttpNetworkRequestPrivate::header(request, | - | ||||||||||||||||||
669 | (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy))); | - | ||||||||||||||||||
670 | #else | - | ||||||||||||||||||
671 | pipeline.append(QHttpNetworkRequestPrivate::header(request, false)); | - | ||||||||||||||||||
672 | #endif | - | ||||||||||||||||||
673 | - | |||||||||||||||||||
674 | alreadyPipelinedRequests.append(pair); | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | // pipelineFlush() needs to be called at some point afterwards | - | ||||||||||||||||||
677 | } executed 401 times by 2 tests: end of block Executed by:
| 401 | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | void QHttpNetworkConnectionChannel::pipelineFlush() | - | ||||||||||||||||||
680 | { | - | ||||||||||||||||||
681 | if (pipeline.isEmpty())
| 16-194 | ||||||||||||||||||
682 | return; executed 16 times by 1 test: return; Executed by:
| 16 | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | // The goal of this is so that we have everything in one TCP packet. | - | ||||||||||||||||||
685 | // For the Unbuffered QTcpSocket this is manually needed, the buffered | - | ||||||||||||||||||
686 | // QTcpSocket does it automatically. | - | ||||||||||||||||||
687 | // Also, sometimes the OS does it for us (Nagle's algorithm) but that | - | ||||||||||||||||||
688 | // happens only sometimes. | - | ||||||||||||||||||
689 | socket->write(pipeline); | - | ||||||||||||||||||
690 | pipeline.clear(); | - | ||||||||||||||||||
691 | } executed 194 times by 2 tests: end of block Executed by:
| 194 | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | - | |||||||||||||||||||
694 | void QHttpNetworkConnectionChannel::closeAndResendCurrentRequest() | - | ||||||||||||||||||
695 | { | - | ||||||||||||||||||
696 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
697 | close(); | - | ||||||||||||||||||
698 | if (reply)
| 0-65 | ||||||||||||||||||
699 | resendCurrent = true; executed 65 times by 2 tests: resendCurrent = true; Executed by:
| 65 | ||||||||||||||||||
700 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-65 | ||||||||||||||||||
701 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 65 times by 2 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 65 | ||||||||||||||||||
702 | } executed 65 times by 2 tests: end of block Executed by:
| 65 | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | void QHttpNetworkConnectionChannel::resendCurrentRequest() | - | ||||||||||||||||||
705 | { | - | ||||||||||||||||||
706 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
707 | if (reply)
| 6-28 | ||||||||||||||||||
708 | resendCurrent = true; executed 28 times by 3 tests: resendCurrent = true; Executed by:
| 28 | ||||||||||||||||||
709 | if (qobject_cast<QHttpNetworkConnection*>(connection))
| 0-34 | ||||||||||||||||||
710 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 34 times by 3 tests: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 34 | ||||||||||||||||||
711 | } executed 34 times by 3 tests: end of block Executed by:
| 34 | ||||||||||||||||||
712 | - | |||||||||||||||||||
713 | bool QHttpNetworkConnectionChannel::isSocketBusy() const | - | ||||||||||||||||||
714 | { | - | ||||||||||||||||||
715 | return (state & QHttpNetworkConnectionChannel::BusyState); executed 5420 times by 6 tests: return (state & QHttpNetworkConnectionChannel::BusyState); Executed by:
| 5420 | ||||||||||||||||||
716 | } | - | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | bool QHttpNetworkConnectionChannel::isSocketWriting() const | - | ||||||||||||||||||
719 | { | - | ||||||||||||||||||
720 | return (state & QHttpNetworkConnectionChannel::WritingState); executed 3023 times by 3 tests: return (state & QHttpNetworkConnectionChannel::WritingState); Executed by:
| 3023 | ||||||||||||||||||
721 | } | - | ||||||||||||||||||
722 | - | |||||||||||||||||||
723 | bool QHttpNetworkConnectionChannel::isSocketWaiting() const | - | ||||||||||||||||||
724 | { | - | ||||||||||||||||||
725 | return (state & QHttpNetworkConnectionChannel::WaitingState); executed 9569 times by 7 tests: return (state & QHttpNetworkConnectionChannel::WaitingState); Executed by:
| 9569 | ||||||||||||||||||
726 | } | - | ||||||||||||||||||
727 | - | |||||||||||||||||||
728 | bool QHttpNetworkConnectionChannel::isSocketReading() const | - | ||||||||||||||||||
729 | { | - | ||||||||||||||||||
730 | return (state & QHttpNetworkConnectionChannel::ReadingState); executed 8408 times by 7 tests: return (state & QHttpNetworkConnectionChannel::ReadingState); Executed by:
| 8408 | ||||||||||||||||||
731 | } | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | void QHttpNetworkConnectionChannel::_q_bytesWritten(qint64 bytes) | - | ||||||||||||||||||
734 | { | - | ||||||||||||||||||
735 | Q_UNUSED(bytes); | - | ||||||||||||||||||
736 | if (ssl) {
| 953-1903 | ||||||||||||||||||
737 | // In the SSL case we want to send data from encryptedBytesWritten signal since that one | - | ||||||||||||||||||
738 | // is the one going down to the actual network, not only into some SSL buffer. | - | ||||||||||||||||||
739 | return; executed 1903 times by 3 tests: return; Executed by:
| 1903 | ||||||||||||||||||
740 | } | - | ||||||||||||||||||
741 | - | |||||||||||||||||||
742 | // bytes have been written to the socket. write even more of them :) | - | ||||||||||||||||||
743 | if (isSocketWriting())
| 230-723 | ||||||||||||||||||
744 | sendRequest(); executed 230 times by 1 test: sendRequest(); Executed by:
| 230 | ||||||||||||||||||
745 | // otherwise we do nothing | - | ||||||||||||||||||
746 | } executed 953 times by 2 tests: end of block Executed by:
| 953 | ||||||||||||||||||
747 | - | |||||||||||||||||||
748 | void QHttpNetworkConnectionChannel::_q_disconnected() | - | ||||||||||||||||||
749 | { | - | ||||||||||||||||||
750 | if (state == QHttpNetworkConnectionChannel::ClosingState) {
| 246-459 | ||||||||||||||||||
751 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
752 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
753 | return; executed 246 times by 5 tests: return; Executed by:
| 246 | ||||||||||||||||||
754 | } | - | ||||||||||||||||||
755 | - | |||||||||||||||||||
756 | // read the available data before closing (also done in _q_error for other codepaths) | - | ||||||||||||||||||
757 | if ((isSocketWaiting() || isSocketReading()) && socket->bytesAvailable()) {
| 0-459 | ||||||||||||||||||
758 | if (reply) {
| 0 | ||||||||||||||||||
759 | state = QHttpNetworkConnectionChannel::ReadingState; | - | ||||||||||||||||||
760 | _q_receiveReply(); | - | ||||||||||||||||||
761 | } never executed: end of block | 0 | ||||||||||||||||||
762 | } else if (state == QHttpNetworkConnectionChannel::IdleState && resendCurrent) { never executed: end of block
| 0-452 | ||||||||||||||||||
763 | // re-sending request because the socket was in ClosingState | - | ||||||||||||||||||
764 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
765 | } never executed: end of block | 0 | ||||||||||||||||||
766 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | pendingEncrypt = false; | - | ||||||||||||||||||
771 | } executed 459 times by 7 tests: end of block Executed by:
| 459 | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | - | |||||||||||||||||||
774 | void QHttpNetworkConnectionChannel::_q_connected() | - | ||||||||||||||||||
775 | { | - | ||||||||||||||||||
776 | // For the Happy Eyeballs we need to check if this is the first channel to connect. | - | ||||||||||||||||||
777 | if (connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::HostLookupPending || connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4or6) {
| 0-782 | ||||||||||||||||||
778 | if (connection->d_func()->delayedConnectionTimer.isActive())
| 4-120 | ||||||||||||||||||
779 | connection->d_func()->delayedConnectionTimer.stop(); executed 4 times by 2 tests: connection->d_func()->delayedConnectionTimer.stop(); Executed by:
| 4 | ||||||||||||||||||
780 | if (networkLayerPreference == QAbstractSocket::IPv4Protocol)
| 0-124 | ||||||||||||||||||
781 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; executed 124 times by 2 tests: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; Executed by:
| 124 | ||||||||||||||||||
782 | else if (networkLayerPreference == QAbstractSocket::IPv6Protocol)
| 0 | ||||||||||||||||||
783 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | 0 | ||||||||||||||||||
784 | else { | - | ||||||||||||||||||
785 | if (socket->peerAddress().protocol() == QAbstractSocket::IPv4Protocol)
| 0 | ||||||||||||||||||
786 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv4; | 0 | ||||||||||||||||||
787 | else | - | ||||||||||||||||||
788 | connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; never executed: connection->d_func()->networkLayerState = QHttpNetworkConnectionPrivate::IPv6; | 0 | ||||||||||||||||||
789 | } | - | ||||||||||||||||||
790 | connection->d_func()->networkLayerDetected(networkLayerPreference); | - | ||||||||||||||||||
791 | } else { executed 124 times by 2 tests: end of block Executed by:
| 124 | ||||||||||||||||||
792 | if (((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv4) && (networkLayerPreference != QAbstractSocket::IPv4Protocol))
| 0-657 | ||||||||||||||||||
793 | || ((connection->d_func()->networkLayerState == QHttpNetworkConnectionPrivate::IPv6) && (networkLayerPreference != QAbstractSocket::IPv6Protocol))) {
| 0-657 | ||||||||||||||||||
794 | close(); | - | ||||||||||||||||||
795 | // This is the second connection so it has to be closed and we can schedule it for another request. | - | ||||||||||||||||||
796 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
797 | return; never executed: return; | 0 | ||||||||||||||||||
798 | } | - | ||||||||||||||||||
799 | //The connections networkLayerState had already been decided. | - | ||||||||||||||||||
800 | } executed 658 times by 8 tests: end of block Executed by:
| 658 | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | // improve performance since we get the request sent by the kernel ASAP | - | ||||||||||||||||||
803 | //socket->setSocketOption(QAbstractSocket::LowDelayOption, 1); | - | ||||||||||||||||||
804 | // We have this commented out now. It did not have the effect we wanted. If we want to | - | ||||||||||||||||||
805 | // do this properly, Qt has to combine multiple HTTP requests into one buffer | - | ||||||||||||||||||
806 | // and send this to the kernel in one syscall and then the kernel immediately sends | - | ||||||||||||||||||
807 | // it as one TCP packet because of TCP_NODELAY. | - | ||||||||||||||||||
808 | // However, this code is currently not in Qt, so we rely on the kernel combining | - | ||||||||||||||||||
809 | // the requests into one TCP packet. | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | // not sure yet if it helps, but it makes sense | - | ||||||||||||||||||
812 | socket->setSocketOption(QAbstractSocket::KeepAliveOption, 1); | - | ||||||||||||||||||
813 | - | |||||||||||||||||||
814 | pipeliningSupported = QHttpNetworkConnectionChannel::PipeliningSupportUnknown; | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | // ### FIXME: if the server closes the connection unexpectedly, we shouldn't send the same broken request again! | - | ||||||||||||||||||
817 | //channels[i].reconnectAttempts = 2; | - | ||||||||||||||||||
818 | if (ssl || pendingEncrypt) { // FIXME: Didn't work properly with pendingEncrypt only, we should refactor this into an EncrypingState
| 0-662 | ||||||||||||||||||
819 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
820 | if (connection->sslContext().isNull()) {
| 25-95 | ||||||||||||||||||
821 | // this socket is making the 1st handshake for this connection, | - | ||||||||||||||||||
822 | // we need to set the SSL context so new sockets can reuse it | - | ||||||||||||||||||
823 | QSharedPointer<QSslContext> socketSslContext = QSslSocketPrivate::sslContext(static_cast<QSslSocket*>(socket)); | - | ||||||||||||||||||
824 | if (!socketSslContext.isNull())
| 0-95 | ||||||||||||||||||
825 | connection->setSslContext(socketSslContext); executed 95 times by 3 tests: connection->setSslContext(socketSslContext); Executed by:
| 95 | ||||||||||||||||||
826 | } executed 95 times by 3 tests: end of block Executed by:
| 95 | ||||||||||||||||||
827 | #endif | - | ||||||||||||||||||
828 | } else { executed 120 times by 3 tests: end of block Executed by:
| 120 | ||||||||||||||||||
829 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
830 | if (!reply)
| 137-525 | ||||||||||||||||||
831 | connection->d_func()->dequeueRequest(socket); executed 525 times by 9 tests: connection->d_func()->dequeueRequest(socket); Executed by:
| 525 | ||||||||||||||||||
832 | if (reply)
| 2-660 | ||||||||||||||||||
833 | sendRequest(); executed 660 times by 9 tests: sendRequest(); Executed by:
| 660 | ||||||||||||||||||
834 | } executed 662 times by 9 tests: end of block Executed by:
| 662 | ||||||||||||||||||
835 | } | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | - | |||||||||||||||||||
838 | void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socketError) | - | ||||||||||||||||||
839 | { | - | ||||||||||||||||||
840 | if (!socket)
| 0-199 | ||||||||||||||||||
841 | return; never executed: return; | 0 | ||||||||||||||||||
842 | QNetworkReply::NetworkError errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
843 | - | |||||||||||||||||||
844 | switch (socketError) { | - | ||||||||||||||||||
845 | case QAbstractSocket::HostNotFoundError: executed 2 times by 1 test: case QAbstractSocket::HostNotFoundError: Executed by:
| 2 | ||||||||||||||||||
846 | errorCode = QNetworkReply::HostNotFoundError; | - | ||||||||||||||||||
847 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
848 | case QAbstractSocket::ConnectionRefusedError: executed 124 times by 2 tests: case QAbstractSocket::ConnectionRefusedError: Executed by:
| 124 | ||||||||||||||||||
849 | errorCode = QNetworkReply::ConnectionRefusedError; | - | ||||||||||||||||||
850 | break; executed 124 times by 2 tests: break; Executed by:
| 124 | ||||||||||||||||||
851 | case QAbstractSocket::RemoteHostClosedError: executed 53 times by 4 tests: case QAbstractSocket::RemoteHostClosedError: Executed by:
| 53 | ||||||||||||||||||
852 | // This error for SSL comes twice in a row, first from SSL layer ("The TLS/SSL connection has been closed") then from TCP layer. | - | ||||||||||||||||||
853 | // Depending on timing it can also come three times in a row (first time when we try to write into a closing QSslSocket). | - | ||||||||||||||||||
854 | // The reconnectAttempts handling catches the cases where we can re-send the request. | - | ||||||||||||||||||
855 | if (!reply && state == QHttpNetworkConnectionChannel::IdleState) {
| 8-37 | ||||||||||||||||||
856 | // Not actually an error, it is normal for Keep-Alive connections to close after some time if no request | - | ||||||||||||||||||
857 | // is sent on them. No need to error the other replies below. Just bail out here. | - | ||||||||||||||||||
858 | // The _q_disconnected will handle the possibly pipelined replies | - | ||||||||||||||||||
859 | return; executed 8 times by 2 tests: return; Executed by:
| 8 | ||||||||||||||||||
860 | } else if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
| 0-45 | ||||||||||||||||||
861 | // Try to reconnect/resend before sending an error. | - | ||||||||||||||||||
862 | // While "Reading" the _q_disconnected() will handle this. | - | ||||||||||||||||||
863 | if (reconnectAttempts-- > 0) {
| 6-34 | ||||||||||||||||||
864 | resendCurrentRequest(); | - | ||||||||||||||||||
865 | return; executed 34 times by 3 tests: return; Executed by:
| 34 | ||||||||||||||||||
866 | } else { | - | ||||||||||||||||||
867 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
868 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||||||||||||||
869 | } else if (state == QHttpNetworkConnectionChannel::ReadingState) {
| 0-5 | ||||||||||||||||||
870 | if (!reply)
| 0-5 | ||||||||||||||||||
871 | break; never executed: break; | 0 | ||||||||||||||||||
872 | - | |||||||||||||||||||
873 | if (!reply->d_func()->expectContent()) {
| 0-5 | ||||||||||||||||||
874 | // No content expected, this is a valid way to have the connection closed by the server | - | ||||||||||||||||||
875 | // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState | - | ||||||||||||||||||
876 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
877 | return; never executed: return; | 0 | ||||||||||||||||||
878 | } | - | ||||||||||||||||||
879 | if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
| 0-5 | ||||||||||||||||||
880 | // There was no content-length header and it's not chunked encoding, | - | ||||||||||||||||||
881 | // so this is a valid way to have the connection closed by the server | - | ||||||||||||||||||
882 | // We need to invoke this asynchronously to make sure the state() of the socket is on QAbstractSocket::UnconnectedState | - | ||||||||||||||||||
883 | QMetaObject::invokeMethod(this, "_q_receiveReply", Qt::QueuedConnection); | - | ||||||||||||||||||
884 | return; executed 5 times by 1 test: return; Executed by:
| 5 | ||||||||||||||||||
885 | } | - | ||||||||||||||||||
886 | // ok, we got a disconnect even though we did not expect it | - | ||||||||||||||||||
887 | // Try to read everything from the socket before we emit the error. | - | ||||||||||||||||||
888 | if (socket->bytesAvailable()) {
| 0 | ||||||||||||||||||
889 | // Read everything from the socket into the reply buffer. | - | ||||||||||||||||||
890 | // we can ignore the readbuffersize as the data is already | - | ||||||||||||||||||
891 | // in memory and we will not receive more data on the socket. | - | ||||||||||||||||||
892 | reply->setReadBufferSize(0); | - | ||||||||||||||||||
893 | reply->setDownstreamLimited(false); | - | ||||||||||||||||||
894 | _q_receiveReply(); | - | ||||||||||||||||||
895 | if (!reply) {
| 0 | ||||||||||||||||||
896 | // No more reply assigned after the previous call? Then it had been finished successfully. | - | ||||||||||||||||||
897 | requeueCurrentlyPipelinedRequests(); | - | ||||||||||||||||||
898 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
899 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
900 | return; never executed: return; | 0 | ||||||||||||||||||
901 | } | - | ||||||||||||||||||
902 | } never executed: end of block | 0 | ||||||||||||||||||
903 | - | |||||||||||||||||||
904 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
905 | } else { never executed: end of block | 0 | ||||||||||||||||||
906 | errorCode = QNetworkReply::RemoteHostClosedError; | - | ||||||||||||||||||
907 | } never executed: end of block | 0 | ||||||||||||||||||
908 | break; executed 6 times by 2 tests: break; Executed by:
| 6 | ||||||||||||||||||
909 | case QAbstractSocket::SocketTimeoutError: never executed: case QAbstractSocket::SocketTimeoutError: | 0 | ||||||||||||||||||
910 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
911 | if (state == QHttpNetworkConnectionChannel::WritingState && (reconnectAttempts-- > 0)) {
| 0 | ||||||||||||||||||
912 | resendCurrentRequest(); | - | ||||||||||||||||||
913 | return; never executed: return; | 0 | ||||||||||||||||||
914 | } | - | ||||||||||||||||||
915 | errorCode = QNetworkReply::TimeoutError; | - | ||||||||||||||||||
916 | break; never executed: break; | 0 | ||||||||||||||||||
917 | case QAbstractSocket::ProxyAuthenticationRequiredError: executed 5 times by 2 tests: case QAbstractSocket::ProxyAuthenticationRequiredError: Executed by:
| 5 | ||||||||||||||||||
918 | errorCode = QNetworkReply::ProxyAuthenticationRequiredError; | - | ||||||||||||||||||
919 | break; executed 5 times by 2 tests: break; Executed by:
| 5 | ||||||||||||||||||
920 | case QAbstractSocket::SslHandshakeFailedError: executed 12 times by 3 tests: case QAbstractSocket::SslHandshakeFailedError: Executed by:
| 12 | ||||||||||||||||||
921 | errorCode = QNetworkReply::SslHandshakeFailedError; | - | ||||||||||||||||||
922 | break; executed 12 times by 3 tests: break; Executed by:
| 12 | ||||||||||||||||||
923 | case QAbstractSocket::ProxyConnectionClosedError: never executed: case QAbstractSocket::ProxyConnectionClosedError: | 0 | ||||||||||||||||||
924 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
925 | if (reconnectAttempts-- > 0) {
| 0 | ||||||||||||||||||
926 | resendCurrentRequest(); | - | ||||||||||||||||||
927 | return; never executed: return; | 0 | ||||||||||||||||||
928 | } | - | ||||||||||||||||||
929 | errorCode = QNetworkReply::ProxyConnectionClosedError; | - | ||||||||||||||||||
930 | break; never executed: break; | 0 | ||||||||||||||||||
931 | case QAbstractSocket::ProxyConnectionTimeoutError: never executed: case QAbstractSocket::ProxyConnectionTimeoutError: | 0 | ||||||||||||||||||
932 | // try to reconnect/resend before sending an error. | - | ||||||||||||||||||
933 | if (reconnectAttempts-- > 0) {
| 0 | ||||||||||||||||||
934 | resendCurrentRequest(); | - | ||||||||||||||||||
935 | return; never executed: return; | 0 | ||||||||||||||||||
936 | } | - | ||||||||||||||||||
937 | errorCode = QNetworkReply::ProxyTimeoutError; | - | ||||||||||||||||||
938 | break; never executed: break; | 0 | ||||||||||||||||||
939 | default: executed 3 times by 2 tests: default: Executed by:
| 3 | ||||||||||||||||||
940 | // all other errors are treated as NetworkError | - | ||||||||||||||||||
941 | errorCode = QNetworkReply::UnknownNetworkError; | - | ||||||||||||||||||
942 | break; executed 3 times by 2 tests: break; Executed by:
| 3 | ||||||||||||||||||
943 | } | - | ||||||||||||||||||
944 | QPointer<QHttpNetworkConnection> that = connection; | - | ||||||||||||||||||
945 | QString errorString = connection->d_func()->errorDetail(errorCode, socket, socket->errorString()); | - | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | // In the HostLookupPending state the channel should not emit the error. | - | ||||||||||||||||||
948 | // This will instead be handled by the connection. | - | ||||||||||||||||||
949 | if (!connection->d_func()->shouldEmitChannelError(socket))
| 30-122 | ||||||||||||||||||
950 | return; executed 122 times by 2 tests: return; Executed by:
| 122 | ||||||||||||||||||
951 | - | |||||||||||||||||||
952 | // emit error for all waiting replies | - | ||||||||||||||||||
953 | do { | - | ||||||||||||||||||
954 | // Need to dequeu the request so that we can emit the error. | - | ||||||||||||||||||
955 | if (!reply)
| 12-20 | ||||||||||||||||||
956 | connection->d_func()->dequeueRequest(socket); executed 12 times by 3 tests: connection->d_func()->dequeueRequest(socket); Executed by:
| 12 | ||||||||||||||||||
957 | - | |||||||||||||||||||
958 | if (reply) {
| 3-29 | ||||||||||||||||||
959 | reply->d_func()->errorString = errorString; | - | ||||||||||||||||||
960 | emit reply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
961 | reply = 0; | - | ||||||||||||||||||
962 | if (protocolHandler)
| 12-17 | ||||||||||||||||||
963 | protocolHandler->setReply(0); executed 12 times by 3 tests: protocolHandler->setReply(0); Executed by:
| 12 | ||||||||||||||||||
964 | } executed 29 times by 3 tests: end of block Executed by:
| 29 | ||||||||||||||||||
965 | } while (!connection->d_func()->highPriorityQueue.isEmpty() executed 32 times by 4 tests: end of block Executed by:
| 0-32 | ||||||||||||||||||
966 | || !connection->d_func()->lowPriorityQueue.isEmpty());
| 2-30 | ||||||||||||||||||
967 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
968 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-27 | ||||||||||||||||||
969 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
970 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 3 | ||||||||||||||||||
971 | // emit error for all replies | - | ||||||||||||||||||
972 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
973 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
974 | emit currentReply->finishedWithError(errorCode, errorString); | - | ||||||||||||||||||
975 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
976 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
977 | #endif // QT_NO_SSL | - | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | // send the next request | - | ||||||||||||||||||
980 | QMetaObject::invokeMethod(that, "_q_startNextRequest", Qt::QueuedConnection); | - | ||||||||||||||||||
981 | - | |||||||||||||||||||
982 | if (that) {
| 0-30 | ||||||||||||||||||
983 | //signal emission triggered event loop | - | ||||||||||||||||||
984 | if (!socket)
| 0-30 | ||||||||||||||||||
985 | state = QHttpNetworkConnectionChannel::IdleState; never executed: state = QHttpNetworkConnectionChannel::IdleState; | 0 | ||||||||||||||||||
986 | else if (socket->state() == QAbstractSocket::UnconnectedState)
| 13-17 | ||||||||||||||||||
987 | state = QHttpNetworkConnectionChannel::IdleState; executed 17 times by 4 tests: state = QHttpNetworkConnectionChannel::IdleState; Executed by:
| 17 | ||||||||||||||||||
988 | else | - | ||||||||||||||||||
989 | state = QHttpNetworkConnectionChannel::ClosingState; executed 13 times by 2 tests: state = QHttpNetworkConnectionChannel::ClosingState; Executed by:
| 13 | ||||||||||||||||||
990 | - | |||||||||||||||||||
991 | // pendingEncrypt must only be true in between connected and encrypted states | - | ||||||||||||||||||
992 | pendingEncrypt = false; | - | ||||||||||||||||||
993 | } executed 30 times by 4 tests: end of block Executed by:
| 30 | ||||||||||||||||||
994 | } executed 30 times by 4 tests: end of block Executed by:
| 30 | ||||||||||||||||||
995 | - | |||||||||||||||||||
996 | #ifndef QT_NO_NETWORKPROXY | - | ||||||||||||||||||
997 | void QHttpNetworkConnectionChannel::_q_proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator* auth) | - | ||||||||||||||||||
998 | { | - | ||||||||||||||||||
999 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1000 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 3-39 | ||||||||||||||||||
1001 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); | - | ||||||||||||||||||
1002 | } else { // HTTP executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
1003 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1004 | // Need to dequeue the request before we can emit the error. | - | ||||||||||||||||||
1005 | if (!reply)
| 2-37 | ||||||||||||||||||
1006 | connection->d_func()->dequeueRequest(socket); executed 37 times by 1 test: connection->d_func()->dequeueRequest(socket); Executed by:
| 37 | ||||||||||||||||||
1007 | if (reply)
| 0-39 | ||||||||||||||||||
1008 | connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); executed 39 times by 1 test: connection->d_func()->emitProxyAuthenticationRequired(this, proxy, auth); Executed by:
| 39 | ||||||||||||||||||
1009 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1010 | } executed 39 times by 1 test: end of block Executed by:
| 39 | ||||||||||||||||||
1011 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1012 | } | - | ||||||||||||||||||
1013 | #endif | - | ||||||||||||||||||
1014 | - | |||||||||||||||||||
1015 | void QHttpNetworkConnectionChannel::_q_uploadDataReadyRead() | - | ||||||||||||||||||
1016 | { | - | ||||||||||||||||||
1017 | if (reply)
| 0-1964 | ||||||||||||||||||
1018 | sendRequest(); executed 1964 times by 2 tests: sendRequest(); Executed by:
| 1964 | ||||||||||||||||||
1019 | } executed 1964 times by 2 tests: end of block Executed by:
| 1964 | ||||||||||||||||||
1020 | - | |||||||||||||||||||
1021 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1022 | void QHttpNetworkConnectionChannel::_q_encrypted() | - | ||||||||||||||||||
1023 | { | - | ||||||||||||||||||
1024 | QSslSocket *sslSocket = qobject_cast<QSslSocket *>(socket); | - | ||||||||||||||||||
1025 | Q_ASSERT(sslSocket); | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | if (!protocolHandler) {
| 10-90 | ||||||||||||||||||
1028 | switch (sslSocket->sslConfiguration().nextProtocolNegotiationStatus()) { | - | ||||||||||||||||||
1029 | case QSslConfiguration::NextProtocolNegotiationNegotiated: /* fall through */ executed 6 times by 1 test: case QSslConfiguration::NextProtocolNegotiationNegotiated: Executed by:
| 6 | ||||||||||||||||||
1030 | case QSslConfiguration::NextProtocolNegotiationUnsupported: { never executed: case QSslConfiguration::NextProtocolNegotiationUnsupported: | 0 | ||||||||||||||||||
1031 | QByteArray nextProtocol = sslSocket->sslConfiguration().nextNegotiatedProtocol(); | - | ||||||||||||||||||
1032 | if (nextProtocol == QSslConfiguration::NextProtocolHttp1_1) {
| 0-6 | ||||||||||||||||||
1033 | // fall through to create a QHttpProtocolHandler | - | ||||||||||||||||||
1034 | } else if (nextProtocol == QSslConfiguration::NextProtocolSpdy3_0) { never executed: end of block
| 0-6 | ||||||||||||||||||
1035 | protocolHandler.reset(new QSpdyProtocolHandler(this)); | - | ||||||||||||||||||
1036 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeSPDY); | - | ||||||||||||||||||
1037 | // no need to re-queue requests, if SPDY was enabled on the request it | - | ||||||||||||||||||
1038 | // has gone to the SPDY queue already | - | ||||||||||||||||||
1039 | break; executed 6 times by 1 test: break; Executed by:
| 6 | ||||||||||||||||||
1040 | } else { | - | ||||||||||||||||||
1041 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
1042 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
1043 | break; never executed: break; | 0 | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | } | - | ||||||||||||||||||
1046 | case QSslConfiguration::NextProtocolNegotiationNone: code before this statement never executed: case QSslConfiguration::NextProtocolNegotiationNone: executed 84 times by 3 tests: case QSslConfiguration::NextProtocolNegotiationNone: Executed by:
| 0-84 | ||||||||||||||||||
1047 | protocolHandler.reset(new QHttpProtocolHandler(this)); | - | ||||||||||||||||||
1048 | connection->setConnectionType(QHttpNetworkConnection::ConnectionTypeHTTP); | - | ||||||||||||||||||
1049 | // re-queue requests from SPDY queue to HTTP queue, if any | - | ||||||||||||||||||
1050 | requeueSpdyRequests(); | - | ||||||||||||||||||
1051 | break; executed 84 times by 3 tests: break; Executed by:
| 84 | ||||||||||||||||||
1052 | default: never executed: default: | 0 | ||||||||||||||||||
1053 | emitFinishedWithError(QNetworkReply::SslHandshakeFailedError, | - | ||||||||||||||||||
1054 | "detected unknown Next Protocol Negotiation protocol"); | - | ||||||||||||||||||
1055 | } never executed: end of block | 0 | ||||||||||||||||||
1056 | } | - | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | if (!socket)
| 0-100 | ||||||||||||||||||
1059 | return; // ### error never executed: return; | 0 | ||||||||||||||||||
1060 | state = QHttpNetworkConnectionChannel::IdleState; | - | ||||||||||||||||||
1061 | pendingEncrypt = false; | - | ||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeSPDY) {
| 6-94 | ||||||||||||||||||
1064 | // we call setSpdyWasUsed(true) on the replies in the SPDY handler when the request is sent | - | ||||||||||||||||||
1065 | if (spdyRequestsToSend.count() > 0)
| 0-6 | ||||||||||||||||||
1066 | // wait for data from the server first (e.g. initial window, max concurrent requests) | - | ||||||||||||||||||
1067 | QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); executed 6 times by 1 test: QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); Executed by:
| 6 | ||||||||||||||||||
1068 | } else { // HTTP executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||||||||
1069 | if (!reply)
| 37-57 | ||||||||||||||||||
1070 | connection->d_func()->dequeueRequest(socket); executed 57 times by 1 test: connection->d_func()->dequeueRequest(socket); Executed by:
| 57 | ||||||||||||||||||
1071 | if (reply) {
| 4-90 | ||||||||||||||||||
1072 | reply->setSpdyWasUsed(false); | - | ||||||||||||||||||
1073 | Q_ASSERT(reply->d_func()->connectionChannel == this); | - | ||||||||||||||||||
1074 | emit reply->encrypted(); | - | ||||||||||||||||||
1075 | } executed 90 times by 3 tests: end of block Executed by:
| 90 | ||||||||||||||||||
1076 | if (reply)
| 4-90 | ||||||||||||||||||
1077 | sendRequest(); executed 90 times by 3 tests: sendRequest(); Executed by:
| 90 | ||||||||||||||||||
1078 | } executed 94 times by 3 tests: end of block Executed by:
| 94 | ||||||||||||||||||
1079 | } | - | ||||||||||||||||||
1080 | - | |||||||||||||||||||
1081 | void QHttpNetworkConnectionChannel::requeueSpdyRequests() | - | ||||||||||||||||||
1082 | { | - | ||||||||||||||||||
1083 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
1084 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0-84 | ||||||||||||||||||
1085 | connection->d_func()->requeueRequest(spdyPairs.at(a)); | - | ||||||||||||||||||
1086 | } never executed: end of block | 0 | ||||||||||||||||||
1087 | spdyRequestsToSend.clear(); | - | ||||||||||||||||||
1088 | } executed 84 times by 3 tests: end of block Executed by:
| 84 | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | void QHttpNetworkConnectionChannel::emitFinishedWithError(QNetworkReply::NetworkError error, | - | ||||||||||||||||||
1091 | const char *message) | - | ||||||||||||||||||
1092 | { | - | ||||||||||||||||||
1093 | if (reply)
| 0 | ||||||||||||||||||
1094 | emit reply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); never executed: reply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | 0 | ||||||||||||||||||
1095 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
1096 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0 | ||||||||||||||||||
1097 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
1098 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
1099 | emit currentReply->finishedWithError(error, QHttpNetworkConnectionChannel::tr(message)); | - | ||||||||||||||||||
1100 | } never executed: end of block | 0 | ||||||||||||||||||
1101 | } never executed: end of block | 0 | ||||||||||||||||||
1102 | - | |||||||||||||||||||
1103 | void QHttpNetworkConnectionChannel::_q_sslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
1104 | { | - | ||||||||||||||||||
1105 | if (!socket)
| 0-53 | ||||||||||||||||||
1106 | return; never executed: return; | 0 | ||||||||||||||||||
1107 | //QNetworkReply::NetworkError errorCode = QNetworkReply::ProtocolFailure; | - | ||||||||||||||||||
1108 | // Also pause the connection because socket notifiers may fire while an user | - | ||||||||||||||||||
1109 | // dialog is displaying | - | ||||||||||||||||||
1110 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
1111 | if (pendingEncrypt && !reply)
| 0-53 | ||||||||||||||||||
1112 | connection->d_func()->dequeueRequest(socket); executed 47 times by 3 tests: connection->d_func()->dequeueRequest(socket); Executed by:
| 47 | ||||||||||||||||||
1113 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 7-46 | ||||||||||||||||||
1114 | if (reply)
| 3-43 | ||||||||||||||||||
1115 | emit reply->sslErrors(errors); executed 43 times by 3 tests: reply->sslErrors(errors); Executed by:
| 43 | ||||||||||||||||||
1116 | } executed 46 times by 3 tests: end of block Executed by:
| 46 | ||||||||||||||||||
1117 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1118 | else { // SPDY | - | ||||||||||||||||||
1119 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
1120 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 7 | ||||||||||||||||||
1121 | // emit SSL errors for all replies | - | ||||||||||||||||||
1122 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
1123 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
1124 | emit currentReply->sslErrors(errors); | - | ||||||||||||||||||
1125 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
1126 | } executed 7 times by 1 test: end of block Executed by:
| 7 | ||||||||||||||||||
1127 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1128 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
1129 | } executed 53 times by 3 tests: end of block Executed by:
| 53 | ||||||||||||||||||
1130 | - | |||||||||||||||||||
1131 | void QHttpNetworkConnectionChannel::_q_preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *authenticator) | - | ||||||||||||||||||
1132 | { | - | ||||||||||||||||||
1133 | connection->d_func()->pauseConnection(); | - | ||||||||||||||||||
1134 | - | |||||||||||||||||||
1135 | if (pendingEncrypt && !reply)
| 0 | ||||||||||||||||||
1136 | connection->d_func()->dequeueRequest(socket); never executed: connection->d_func()->dequeueRequest(socket); | 0 | ||||||||||||||||||
1137 | - | |||||||||||||||||||
1138 | if (connection->connectionType() == QHttpNetworkConnection::ConnectionTypeHTTP) {
| 0 | ||||||||||||||||||
1139 | if (reply)
| 0 | ||||||||||||||||||
1140 | emit reply->preSharedKeyAuthenticationRequired(authenticator); never executed: reply->preSharedKeyAuthenticationRequired(authenticator); | 0 | ||||||||||||||||||
1141 | } else { never executed: end of block | 0 | ||||||||||||||||||
1142 | QList<HttpMessagePair> spdyPairs = spdyRequestsToSend.values(); | - | ||||||||||||||||||
1143 | for (int a = 0; a < spdyPairs.count(); ++a) {
| 0 | ||||||||||||||||||
1144 | // emit SSL errors for all replies | - | ||||||||||||||||||
1145 | QHttpNetworkReply *currentReply = spdyPairs.at(a).second; | - | ||||||||||||||||||
1146 | Q_ASSERT(currentReply); | - | ||||||||||||||||||
1147 | emit currentReply->preSharedKeyAuthenticationRequired(authenticator); | - | ||||||||||||||||||
1148 | } never executed: end of block | 0 | ||||||||||||||||||
1149 | } never executed: end of block | 0 | ||||||||||||||||||
1150 | - | |||||||||||||||||||
1151 | connection->d_func()->resumeConnection(); | - | ||||||||||||||||||
1152 | } never executed: end of block | 0 | ||||||||||||||||||
1153 | - | |||||||||||||||||||
1154 | void QHttpNetworkConnectionChannel::_q_encryptedBytesWritten(qint64 bytes) | - | ||||||||||||||||||
1155 | { | - | ||||||||||||||||||
1156 | Q_UNUSED(bytes); | - | ||||||||||||||||||
1157 | // bytes have been written to the socket. write even more of them :) | - | ||||||||||||||||||
1158 | if (isSocketWriting())
| 883-1187 | ||||||||||||||||||
1159 | sendRequest(); executed 883 times by 1 test: sendRequest(); Executed by:
| 883 | ||||||||||||||||||
1160 | // otherwise we do nothing | - | ||||||||||||||||||
1161 | } executed 2070 times by 3 tests: end of block Executed by:
| 2070 | ||||||||||||||||||
1162 | - | |||||||||||||||||||
1163 | #endif | - | ||||||||||||||||||
1164 | - | |||||||||||||||||||
1165 | void QHttpNetworkConnectionChannel::setConnection(QHttpNetworkConnection *c) | - | ||||||||||||||||||
1166 | { | - | ||||||||||||||||||
1167 | // Inlining this function in the header leads to compiler error on | - | ||||||||||||||||||
1168 | // release-armv5, on at least timebox 9.2 and 10.1. | - | ||||||||||||||||||
1169 | connection = c; | - | ||||||||||||||||||
1170 | } executed 3416 times by 8 tests: end of block Executed by:
| 3416 | ||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | QT_END_NAMESPACE | - | ||||||||||||||||||
1173 | - | |||||||||||||||||||
1174 | #include "moc_qhttpnetworkconnectionchannel_p.cpp" | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | #endif // QT_NO_HTTP | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |