1 /****************************************************************************
3 ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtNetwork module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
40 ****************************************************************************/
42 #include "qhttpsocketengine_p.h"
43 #include "qtcpsocket.h"
44 #include "qhostaddress.h"
47 #include "qelapsedtimer.h"
48 #include "qnetworkinterface.h"
50 #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP)
57 QHttpSocketEngine::QHttpSocketEngine(QObject *parent)
58 : QAbstractSocketEngine(*new QHttpSocketEnginePrivate, parent)
62 QHttpSocketEngine::~QHttpSocketEngine()
66 bool QHttpSocketEngine::initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol)
68 Q_D(QHttpSocketEngine);
69 if (type != QAbstractSocket::TcpSocket)
72 setProtocol(protocol);
74 d->socket = new QTcpSocket(this);
75 #ifndef QT_NO_BEARERMANAGEMENT
76 d->socket->setProperty("_q_networkSession", property("_q_networkSession"));
79 // Explicitly disable proxying on the proxy socket itself to avoid
80 // unwanted recursion.
81 d->socket->setProxy(QNetworkProxy::NoProxy);
83 // Intercept all the signals.
84 connect(d->socket, SIGNAL(connected()),
85 this, SLOT(slotSocketConnected()),
86 Qt::DirectConnection);
87 connect(d->socket, SIGNAL(disconnected()),
88 this, SLOT(slotSocketDisconnected()),
89 Qt::DirectConnection);
90 connect(d->socket, SIGNAL(readyRead()),
91 this, SLOT(slotSocketReadNotification()),
92 Qt::DirectConnection);
93 connect(d->socket, SIGNAL(bytesWritten(qint64)),
94 this, SLOT(slotSocketBytesWritten()),
95 Qt::DirectConnection);
96 connect(d->socket, SIGNAL(error(QAbstractSocket::SocketError)),
97 this, SLOT(slotSocketError(QAbstractSocket::SocketError)),
98 Qt::DirectConnection);
99 connect(d->socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
100 this, SLOT(slotSocketStateChanged(QAbstractSocket::SocketState)),
101 Qt::DirectConnection);
106 bool QHttpSocketEngine::initialize(int, QAbstractSocket::SocketState)
111 void QHttpSocketEngine::setProxy(const QNetworkProxy &proxy)
113 Q_D(QHttpSocketEngine);
115 QString user = proxy.user();
117 d->authenticator.setUser(user);
118 QString password = proxy.password();
119 if (!password.isEmpty())
120 d->authenticator.setPassword(password);
123 int QHttpSocketEngine::socketDescriptor() const
125 Q_D(const QHttpSocketEngine);
126 return d->socket ? d->socket->socketDescriptor() : 0;
129 bool QHttpSocketEngine::isValid() const
131 Q_D(const QHttpSocketEngine);
135 bool QHttpSocketEngine::connectInternal()
137 Q_D(QHttpSocketEngine);
139 d->credentialsSent = false;
141 // If the handshake is done, enter ConnectedState state and return true.
142 if (d->state == Connected) {
143 qWarning("QHttpSocketEngine::connectToHost: called when already connected");
144 setState(QAbstractSocket::ConnectedState);
148 if (d->state == ConnectSent && d->socketState != QAbstractSocket::ConnectedState)
149 setState(QAbstractSocket::UnconnectedState);
151 // Handshake isn't done. If unconnected, start connecting.
152 if (d->state == None && d->socket->state() == QAbstractSocket::UnconnectedState) {
153 setState(QAbstractSocket::ConnectingState);
154 //limit buffer in internal socket, data is buffered in the external socket under application control
155 d->socket->setReadBufferSize(65536);
156 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
159 // If connected (might happen right away, at least for localhost services
160 // on some BSD systems), there might already be bytes available.
161 if (bytesAvailable())
162 slotSocketReadNotification();
164 return d->socketState == QAbstractSocket::ConnectedState;
167 bool QHttpSocketEngine::connectToHost(const QHostAddress &address, quint16 port)
169 Q_D(QHttpSocketEngine);
171 setPeerAddress(address);
175 return connectInternal();
178 bool QHttpSocketEngine::connectToHostByName(const QString &hostname, quint16 port)
180 Q_D(QHttpSocketEngine);
182 setPeerAddress(QHostAddress());
184 d->peerName = hostname;
186 return connectInternal();
189 bool QHttpSocketEngine::bind(const QHostAddress &, quint16)
194 bool QHttpSocketEngine::listen()
199 int QHttpSocketEngine::accept()
204 void QHttpSocketEngine::close()
206 Q_D(QHttpSocketEngine);
214 qint64 QHttpSocketEngine::bytesAvailable() const
216 Q_D(const QHttpSocketEngine);
217 return d->readBuffer.size() + (d->socket ? d->socket->bytesAvailable() : 0);
220 qint64 QHttpSocketEngine::read(char *data, qint64 maxlen)
222 Q_D(QHttpSocketEngine);
223 qint64 bytesRead = d->socket->read(data, maxlen);
225 if (d->socket->state() == QAbstractSocket::UnconnectedState
226 && d->socket->bytesAvailable() == 0) {
227 emitReadNotification();
230 if (bytesRead == -1) {
231 // If nothing has been read so far, and the direct socket read
232 // failed, return the socket's error. Otherwise, fall through and
233 // return as much as we read so far.
235 setError(QAbstractSocket::RemoteHostClosedError,
236 QLatin1String("Remote host closed"));
237 setState(QAbstractSocket::UnconnectedState);
243 qint64 QHttpSocketEngine::write(const char *data, qint64 len)
245 Q_D(QHttpSocketEngine);
246 return d->socket->write(data, len);
249 #ifndef QT_NO_UDPSOCKET
250 #ifndef QT_NO_NETWORKINTERFACE
251 bool QHttpSocketEngine::joinMulticastGroup(const QHostAddress &,
252 const QNetworkInterface &)
254 setError(QAbstractSocket::UnsupportedSocketOperationError,
255 QLatin1String("Operation on socket is not supported"));
259 bool QHttpSocketEngine::leaveMulticastGroup(const QHostAddress &,
260 const QNetworkInterface &)
262 setError(QAbstractSocket::UnsupportedSocketOperationError,
263 QLatin1String("Operation on socket is not supported"));
267 QNetworkInterface QHttpSocketEngine::multicastInterface() const
269 return QNetworkInterface();
272 bool QHttpSocketEngine::setMulticastInterface(const QNetworkInterface &)
274 setError(QAbstractSocket::UnsupportedSocketOperationError,
275 QLatin1String("Operation on socket is not supported"));
278 #endif // QT_NO_NETWORKINTERFACE
280 qint64 QHttpSocketEngine::readDatagram(char *, qint64, QHostAddress *,
286 qint64 QHttpSocketEngine::writeDatagram(const char *, qint64, const QHostAddress &,
292 bool QHttpSocketEngine::hasPendingDatagrams() const
297 qint64 QHttpSocketEngine::pendingDatagramSize() const
301 #endif // QT_NO_UDPSOCKET
303 qint64 QHttpSocketEngine::bytesToWrite() const
305 Q_D(const QHttpSocketEngine);
307 return d->socket->bytesToWrite();
313 int QHttpSocketEngine::option(SocketOption option) const
315 Q_D(const QHttpSocketEngine);
317 // convert the enum and call the real socket
318 if (option == QAbstractSocketEngine::LowDelayOption)
319 return d->socket->socketOption(QAbstractSocket::LowDelayOption).toInt();
320 if (option == QAbstractSocketEngine::KeepAliveOption)
321 return d->socket->socketOption(QAbstractSocket::KeepAliveOption).toInt();
326 bool QHttpSocketEngine::setOption(SocketOption option, int value)
328 Q_D(QHttpSocketEngine);
330 // convert the enum and call the real socket
331 if (option == QAbstractSocketEngine::LowDelayOption)
332 d->socket->setSocketOption(QAbstractSocket::LowDelayOption, value);
333 if (option == QAbstractSocketEngine::KeepAliveOption)
334 d->socket->setSocketOption(QAbstractSocket::KeepAliveOption, value);
341 Returns the difference between msecs and elapsed. If msecs is -1,
342 however, -1 is returned.
344 static int qt_timeout_value(int msecs, int elapsed)
349 int timeout = msecs - elapsed;
350 return timeout < 0 ? 0 : timeout;
353 bool QHttpSocketEngine::waitForRead(int msecs, bool *timedOut)
355 Q_D(const QHttpSocketEngine);
357 if (!d->socket || d->socket->state() == QAbstractSocket::UnconnectedState)
360 QElapsedTimer stopWatch;
363 // Wait for more data if nothing is available.
364 if (!d->socket->bytesAvailable()) {
365 if (!d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
366 if (d->socket->state() == QAbstractSocket::UnconnectedState)
368 setError(d->socket->error(), d->socket->errorString());
369 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
375 // If we're not connected yet, wait until we are, or until an error
377 while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
378 // Loop while the protocol handshake is taking place.
381 // Report any error that may occur.
382 if (d->state != Connected) {
383 setError(d->socket->error(), d->socket->errorString());
384 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
391 bool QHttpSocketEngine::waitForWrite(int msecs, bool *timedOut)
393 Q_D(const QHttpSocketEngine);
395 // If we're connected, just forward the call.
396 if (d->state == Connected) {
397 if (d->socket->bytesToWrite()) {
398 if (!d->socket->waitForBytesWritten(msecs)) {
399 if (d->socket->error() == QAbstractSocket::SocketTimeoutError && timedOut)
407 QElapsedTimer stopWatch;
410 // If we're not connected yet, wait until we are, and until bytes have
411 // been received (i.e., the socket has connected, we have sent the
412 // greeting, and then received the response).
413 while (d->state != Connected && d->socket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
414 // Loop while the protocol handshake is taking place.
417 // Report any error that may occur.
418 if (d->state != Connected) {
419 // setError(d->socket->error(), d->socket->errorString());
420 if (timedOut && d->socket->error() == QAbstractSocket::SocketTimeoutError)
427 bool QHttpSocketEngine::waitForReadOrWrite(bool *readyToRead, bool *readyToWrite,
428 bool checkRead, bool checkWrite,
429 int msecs, bool *timedOut)
434 // Not interested in writing? Then we wait for read notifications.
435 bool canRead = waitForRead(msecs, timedOut);
437 *readyToRead = canRead;
441 // Interested in writing? Then we wait for write notifications.
442 bool canWrite = waitForWrite(msecs, timedOut);
444 *readyToWrite = canWrite;
448 bool QHttpSocketEngine::isReadNotificationEnabled() const
450 Q_D(const QHttpSocketEngine);
451 return d->readNotificationEnabled;
454 void QHttpSocketEngine::setReadNotificationEnabled(bool enable)
456 Q_D(QHttpSocketEngine);
457 if (d->readNotificationEnabled == enable)
460 d->readNotificationEnabled = enable;
462 // Enabling read notification can trigger a notification.
463 if (bytesAvailable())
464 slotSocketReadNotification();
468 bool QHttpSocketEngine::isWriteNotificationEnabled() const
470 Q_D(const QHttpSocketEngine);
471 return d->writeNotificationEnabled;
474 void QHttpSocketEngine::setWriteNotificationEnabled(bool enable)
476 Q_D(QHttpSocketEngine);
477 d->writeNotificationEnabled = enable;
478 if (enable && d->state == Connected && d->socket->state() == QAbstractSocket::ConnectedState)
479 QMetaObject::invokeMethod(this, "writeNotification", Qt::QueuedConnection);
482 bool QHttpSocketEngine::isExceptionNotificationEnabled() const
484 Q_D(const QHttpSocketEngine);
485 return d->exceptNotificationEnabled;
488 void QHttpSocketEngine::setExceptionNotificationEnabled(bool enable)
490 Q_D(QHttpSocketEngine);
491 d->exceptNotificationEnabled = enable;
494 void QHttpSocketEngine::slotSocketConnected()
496 Q_D(QHttpSocketEngine);
498 // Send the greeting.
499 const char method[] = "CONNECT";
500 QByteArray peerAddress = d->peerName.isEmpty() ?
501 d->peerAddress.toString().toLatin1() :
502 QUrl::toAce(d->peerName);
503 QByteArray path = peerAddress + ':' + QByteArray::number(d->peerPort);
504 QByteArray data = method;
507 data += " HTTP/1.1\r\n";
508 data += "Proxy-Connection: keep-alive\r\n"
510 QVariant v = property("_q_user-agent");
512 data += v.toByteArray();
514 data += "Mozilla/5.0";
516 "Host: " + peerAddress + "\r\n";
517 QAuthenticatorPrivate *priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
518 //qDebug() << "slotSocketConnected: priv=" << priv << (priv ? (int)priv->method : -1);
519 if (priv && priv->method != QAuthenticatorPrivate::None) {
520 d->credentialsSent = true;
521 data += "Proxy-Authorization: " + priv->calculateResponse(method, path);
525 // qDebug() << ">>>>>>>> sending request" << this;
527 // qDebug() << ">>>>>>>";
528 d->socket->write(data);
529 d->state = ConnectSent;
532 void QHttpSocketEngine::slotSocketDisconnected()
536 void QHttpSocketEngine::slotSocketReadNotification()
538 Q_D(QHttpSocketEngine);
539 if (d->state != Connected && d->socket->bytesAvailable() == 0)
542 if (d->state == Connected) {
543 // Forward as a read notification.
544 if (d->readNotificationEnabled)
545 emitReadNotification();
550 if (d->state == ReadResponseContent) {
551 char dummybuffer[4096];
552 while (d->pendingResponseData) {
553 int read = d->socket->read(dummybuffer, qMin(sizeof(dummybuffer), (size_t)d->pendingResponseData));
555 dummybuffer[read] = 0;
560 d->socket->disconnectFromHost();
561 emitWriteNotification();
564 d->pendingResponseData -= read;
566 if (d->pendingResponseData > 0)
568 d->state = SendAuthentication;
569 slotSocketConnected();
573 // Still in handshake mode. Wait until we've got a full response.
576 d->readBuffer += d->socket->readLine();
577 } while (!(done = d->readBuffer.endsWith("\r\n\r\n")) && d->socket->canReadLine());
584 if (!d->readBuffer.startsWith("HTTP/1.")) {
585 // protocol error, this isn't HTTP
586 d->readBuffer.clear();
588 setState(QAbstractSocket::UnconnectedState);
589 setError(QAbstractSocket::ProxyProtocolError, tr("Did not receive HTTP response from proxy"));
590 emitConnectionNotification();
594 QHttpResponseHeader responseHeader(QString::fromLatin1(d->readBuffer));
595 d->readBuffer.clear(); // we parsed the proxy protocol response. from now on direct socket reading will be done
597 int statusCode = responseHeader.statusCode();
598 QAuthenticatorPrivate *priv = 0;
599 if (statusCode == 200) {
600 d->state = Connected;
601 setLocalAddress(d->socket->localAddress());
602 setLocalPort(d->socket->localPort());
603 setState(QAbstractSocket::ConnectedState);
604 d->authenticator.detach();
605 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
606 priv->hasFailed = false;
607 } else if (statusCode == 407) {
608 if (d->credentialsSent) {
609 //407 response again means the provided username/password were invalid.
610 d->authenticator = QAuthenticator(); //this is needed otherwise parseHttpResponse won't set the state, and then signal isn't emitted.
611 d->authenticator.detach();
612 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
613 priv->hasFailed = true;
615 else if (d->authenticator.isNull())
616 d->authenticator.detach();
617 priv = QAuthenticatorPrivate::getPrivate(d->authenticator);
619 priv->parseHttpResponse(responseHeader, true);
621 if (priv->phase == QAuthenticatorPrivate::Invalid) {
622 // problem parsing the reply
624 setState(QAbstractSocket::UnconnectedState);
625 setError(QAbstractSocket::ProxyProtocolError, tr("Error parsing authentication request from proxy"));
626 emitConnectionNotification();
631 QString proxyConnectionHeader = responseHeader.value(QLatin1String("Proxy-Connection"));
632 // Although most proxies use the unofficial Proxy-Connection header, the Connection header
633 // from http spec is also allowed.
634 if (proxyConnectionHeader.isEmpty())
635 proxyConnectionHeader = responseHeader.value(QLatin1String("Connection"));
636 proxyConnectionHeader = proxyConnectionHeader.toLower();
637 if (proxyConnectionHeader == QLatin1String("close")) {
639 } else if (proxyConnectionHeader == QLatin1String("keep-alive")) {
642 // no Proxy-Connection header, so use the default
643 // HTTP 1.1's default behaviour is to keep persistent connections
644 // HTTP 1.0 or earlier, so we expect the server to close
645 willClose = (responseHeader.majorVersion() * 0x100 + responseHeader.minorVersion()) <= 0x0100;
649 // the server will disconnect, so let's avoid receiving an error
650 // especially since the signal below may trigger a new event loop
651 d->socket->disconnectFromHost();
652 d->socket->readAll();
655 if (priv->phase == QAuthenticatorPrivate::Done)
656 emit proxyAuthenticationRequired(d->proxy, &d->authenticator);
657 // priv->phase will get reset to QAuthenticatorPrivate::Start if the authenticator got modified in the signal above.
658 if (priv->phase == QAuthenticatorPrivate::Done) {
659 setError(QAbstractSocket::ProxyAuthenticationRequiredError, tr("Authentication required"));
660 d->socket->disconnectFromHost();
662 // close the connection if it isn't already and reconnect using the chosen authentication method
663 d->state = SendAuthentication;
665 d->socket->connectToHost(d->proxy.hostName(), d->proxy.port());
668 int contentLength = responseHeader.value(QLatin1String("Content-Length")).toInt(&ok);
669 if (ok && contentLength > 0) {
670 d->state = ReadResponseContent;
671 d->pendingResponseData = contentLength;
672 goto readResponseContent;
674 d->state = SendAuthentication;
675 slotSocketConnected();
682 setState(QAbstractSocket::UnconnectedState);
683 if (statusCode == 403 || statusCode == 405) {
685 // 405 Method Not Allowed
686 setError(QAbstractSocket::SocketAccessError, tr("Proxy denied connection"));
687 } else if (statusCode == 404) {
688 // 404 Not Found: host lookup error
689 setError(QAbstractSocket::HostNotFoundError, QAbstractSocket::tr("Host not found"));
690 } else if (statusCode == 503) {
691 // 503 Service Unavailable: Connection Refused
692 setError(QAbstractSocket::ConnectionRefusedError, QAbstractSocket::tr("Connection refused"));
695 //qWarning("UNEXPECTED RESPONSE: [%s]", responseHeader.toString().toLatin1().data());
696 setError(QAbstractSocket::ProxyProtocolError, tr("Error communicating with HTTP proxy"));
700 // The handshake is done; notify that we're connected (or failed to connect)
701 emitConnectionNotification();
704 void QHttpSocketEngine::slotSocketBytesWritten()
706 Q_D(QHttpSocketEngine);
707 if (d->state == Connected && d->writeNotificationEnabled)
708 emitWriteNotification();
711 void QHttpSocketEngine::slotSocketError(QAbstractSocket::SocketError error)
713 Q_D(QHttpSocketEngine);
714 d->readBuffer.clear();
716 if (d->state != Connected) {
717 // we are in proxy handshaking stages
718 if (error == QAbstractSocket::HostNotFoundError)
719 setError(QAbstractSocket::ProxyNotFoundError, tr("Proxy server not found"));
720 else if (error == QAbstractSocket::ConnectionRefusedError)
721 setError(QAbstractSocket::ProxyConnectionRefusedError, tr("Proxy connection refused"));
722 else if (error == QAbstractSocket::SocketTimeoutError)
723 setError(QAbstractSocket::ProxyConnectionTimeoutError, tr("Proxy server connection timed out"));
724 else if (error == QAbstractSocket::RemoteHostClosedError)
725 setError(QAbstractSocket::ProxyConnectionClosedError, tr("Proxy connection closed prematurely"));
727 setError(error, d->socket->errorString());
728 emitConnectionNotification();
733 if (error == QAbstractSocket::SocketTimeoutError)
734 return; // ignore this error
737 setError(error, d->socket->errorString());
738 if (error != QAbstractSocket::RemoteHostClosedError)
739 qDebug() << "QHttpSocketEngine::slotSocketError: got weird error =" << error;
740 //read notification needs to always be emitted, otherwise the higher layer doesn't get the disconnected signal
741 emitReadNotification();
744 void QHttpSocketEngine::slotSocketStateChanged(QAbstractSocket::SocketState state)
749 void QHttpSocketEngine::emitPendingReadNotification()
751 Q_D(QHttpSocketEngine);
752 d->readNotificationPending = false;
753 if (d->readNotificationEnabled)
754 emit readNotification();
757 void QHttpSocketEngine::emitPendingWriteNotification()
759 Q_D(QHttpSocketEngine);
760 d->writeNotificationPending = false;
761 if (d->writeNotificationEnabled)
762 emit writeNotification();
765 void QHttpSocketEngine::emitPendingConnectionNotification()
767 Q_D(QHttpSocketEngine);
768 d->connectionNotificationPending = false;
769 emit connectionNotification();
772 void QHttpSocketEngine::emitReadNotification()
774 Q_D(QHttpSocketEngine);
775 d->readNotificationActivated = true;
776 // if there is a connection notification pending we have to emit the readNotification
777 // incase there is connection error. This is only needed for Windows, but it does not
778 // hurt in other cases.
779 if ((d->readNotificationEnabled && !d->readNotificationPending) || d->connectionNotificationPending) {
780 d->readNotificationPending = true;
781 QMetaObject::invokeMethod(this, "emitPendingReadNotification", Qt::QueuedConnection);
785 void QHttpSocketEngine::emitWriteNotification()
787 Q_D(QHttpSocketEngine);
788 d->writeNotificationActivated = true;
789 if (d->writeNotificationEnabled && !d->writeNotificationPending) {
790 d->writeNotificationPending = true;
791 QMetaObject::invokeMethod(this, "emitPendingWriteNotification", Qt::QueuedConnection);
795 void QHttpSocketEngine::emitConnectionNotification()
797 Q_D(QHttpSocketEngine);
798 if (!d->connectionNotificationPending) {
799 d->connectionNotificationPending = true;
800 QMetaObject::invokeMethod(this, "emitPendingConnectionNotification", Qt::QueuedConnection);
804 QHttpSocketEnginePrivate::QHttpSocketEnginePrivate()
805 : readNotificationEnabled(false)
806 , writeNotificationEnabled(false)
807 , exceptNotificationEnabled(false)
808 , readNotificationActivated(false)
809 , writeNotificationActivated(false)
810 , readNotificationPending(false)
811 , writeNotificationPending(false)
812 , connectionNotificationPending(false)
813 , credentialsSent(false)
814 , pendingResponseData(0)
817 state = QHttpSocketEngine::None;
820 QHttpSocketEnginePrivate::~QHttpSocketEnginePrivate()
824 QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(QAbstractSocket::SocketType socketType,
825 const QNetworkProxy &proxy,
828 if (socketType != QAbstractSocket::TcpSocket)
831 // proxy type must have been resolved by now
832 if (proxy.type() != QNetworkProxy::HttpProxy)
835 // we only accept active sockets
836 if (!qobject_cast<QAbstractSocket *>(parent))
839 QHttpSocketEngine *engine = new QHttpSocketEngine(parent);
840 engine->setProxy(proxy);
844 QAbstractSocketEngine *QHttpSocketEngineHandler::createSocketEngine(int, QObject *)