8#include "private/qhttpnetworkreply_p.h"
9#include "private/qiodevice_p.h"
13#if !defined(QT_NO_NETWORKPROXY)
80 d->authenticator.setUser(user);
83 d->authenticator.setPassword(password);
89 return d->socket ?
d->socket->socketDescriptor() : -1;
102 d->credentialsSent =
false;
106 qWarning(
"QHttpSocketEngine::connectToHost: called when already connected");
118 d->socket->setReadBufferSize(65536);
119 d->socket->connectToHost(
d->proxy.hostName(),
d->proxy.port());
147 d->peerName = hostname;
154 qWarning(
"Operation is not supported");
162 qWarning(
"Operation is not supported");
169 qWarning(
"Operation is not supported");
187 return d->socket ?
d->socket->bytesAvailable() : 0;
196 &&
d->socket->bytesAvailable() == 0) {
197 emitReadNotification();
200 if (bytesRead == -1) {
218#ifndef QT_NO_UDPSOCKET
219#ifndef QT_NO_NETWORKINTERFACE
223 qWarning(
"Operation is not supported");
231 qWarning(
"Operation is not supported");
243 qWarning(
"Operation is not supported");
251 qWarning(
"Operation is not supported");
257 qWarning(
"Operation is not supported");
264 qWarning(
"Operation is not supported");
271 qWarning(
"Operation is not supported");
280 return d->socket->bytesToWrite();
321 if (!
d->socket->bytesAvailable()) {
325 setError(
d->socket->error(),
d->socket->errorString());
336 setError(
d->socket->error(),
d->socket->errorString());
350 if (
d->socket->bytesToWrite()) {
373 bool checkRead,
bool checkWrite,
382 *readyToRead = canRead;
389 *readyToWrite = canWrite;
408 return d->readNotificationEnabled;
414 if (
d->readNotificationEnabled ==
enable)
417 d->readNotificationEnabled =
enable;
423 emitReadNotification();
431 return d->writeNotificationEnabled;
437 d->writeNotificationEnabled =
enable;
445 return d->exceptNotificationEnabled;
451 d->exceptNotificationEnabled =
enable;
459 const char method[] =
"CONNECT";
467 data +=
" HTTP/1.1\r\n";
468 data +=
"Proxy-Connection: keep-alive\r\n";
470 const auto headers =
d->proxy.headers();
472 data +=
"User-Agent: Mozilla/5.0\r\n";
474 const auto name = headers.nameAt(
i);
476 + headers.valueAt(
i) +
"\r\n";
481 d->credentialsSent =
true;
482 data +=
"Proxy-Authorization: " +
priv->calculateResponse(
method,
path,
d->proxy.hostName());
489 d->socket->write(
data);
500 if (
d->state !=
Connected &&
d->socket->bytesAvailable() == 0)
505 if (
d->readNotificationEnabled)
506 emitReadNotification();
516 bool ok = readHttpHeader();
522 emitConnectionNotification();
530 qint64 skipped =
d->socket->skip(
d->pendingResponseData);
532 d->socket->disconnectFromHost();
533 emitWriteNotification();
536 d->pendingResponseData -=
uint(skipped);
537 if (
d->pendingResponseData > 0)
539 if (
d->reply->statusCode() == 407)
543 int statusCode =
d->reply->statusCode();
545 if (statusCode == 200) {
549 d->inboundStreamCount =
d->outboundStreamCount = 1;
551 d->authenticator.detach();
553 priv->hasFailed =
false;
554 }
else if (statusCode == 407) {
555 if (
d->authenticator.isNull())
556 d->authenticator.detach();
559 const auto headers =
d->reply->header();
560 priv->parseHttpResponse(headers,
true,
d->proxy.hostName());
567 emitConnectionNotification();
577 bool credentialsWasSent =
d->credentialsSent;
578 if (
d->credentialsSent) {
582 d->authenticator.detach();
584 priv->hasFailed =
true;
585 d->credentialsSent =
false;
590 || credentialsWasSent)
595 QByteArray proxyConnectionHeader =
d->reply->headerField(
"Proxy-Connection");
598 if (proxyConnectionHeader.isEmpty())
599 proxyConnectionHeader =
d->reply->headerField(
"Connection");
608 willClose = (
d->reply->majorVersion() * 0x100 +
d->reply->minorVersion()) <= 0x0100;
614 d->socket->disconnectFromHost();
615 d->socket->readAll();
624 d->socket->disconnectFromHost();
629 d->socket->connectToHost(
d->proxy.hostName(),
d->proxy.port());
639 if (statusCode == 403 || statusCode == 405) {
643 }
else if (statusCode == 404) {
646 }
else if (statusCode == 503) {
657 emitConnectionNotification();
660bool QHttpSocketEngine::readHttpHeader()
670 d->reply->d_func()->clearHttpLayerInformation();
674 ok =
d->reply->d_func()->readStatus(
d->socket) != -1;
679 ok =
d->reply->d_func()->readHeader(
d->socket) != -1;
684 bool contentLengthOk;
685 int contentLength =
d->reply->headerField(
"Content-Length").toInt(&contentLengthOk);
686 if (contentLengthOk && contentLength > 0)
687 d->pendingResponseData = contentLength;
696 if (
d->state ==
Connected &&
d->writeNotificationEnabled)
697 emitWriteNotification();
716 emitConnectionNotification();
727 qDebug() <<
"QHttpSocketEngine::slotSocketError: got weird error =" <<
error;
729 emitReadNotification();
737void QHttpSocketEngine::emitPendingReadNotification()
740 d->readNotificationPending =
false;
741 if (
d->readNotificationEnabled)
745void QHttpSocketEngine::emitPendingWriteNotification()
748 d->writeNotificationPending =
false;
749 if (
d->writeNotificationEnabled)
753void QHttpSocketEngine::emitPendingConnectionNotification()
756 d->connectionNotificationPending =
false;
760void QHttpSocketEngine::emitReadNotification()
766 if ((
d->readNotificationEnabled && !
d->readNotificationPending) ||
d->connectionNotificationPending) {
767 d->readNotificationPending =
true;
772void QHttpSocketEngine::emitWriteNotification()
775 if (
d->writeNotificationEnabled && !
d->writeNotificationPending) {
776 d->writeNotificationPending =
true;
781void QHttpSocketEngine::emitConnectionNotification()
784 if (!
d->connectionNotificationPending) {
785 d->connectionNotificationPending =
true;
791 : readNotificationEnabled(
false)
792 , writeNotificationEnabled(
false)
793 , exceptNotificationEnabled(
false)
794 , readNotificationPending(
false)
795 , writeNotificationPending(
false)
796 , connectionNotificationPending(
false)
797 , credentialsSent(
false)
798 , pendingResponseData(0)
821 if (!qobject_cast<QAbstractSocket *>(parent))
838#include "moc_qhttpsocketengine_p.cpp"
QAbstractSocket::SocketError error() const
QAbstractSocket::NetworkLayerProtocol protocol() const
void setPeerPort(quint16 port)
void setPeerAddress(const QHostAddress &address)
void setState(QAbstractSocket::SocketState state)
void setLocalAddress(const QHostAddress &address)
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
QAbstractSocket::SocketState state() const
void setSocketType(QAbstractSocket::SocketType socketType)
QHostAddress peerAddress() const
void setLocalPort(quint16 port)
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
void connectionNotification()
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol)
SocketState
This enum describes the different states in which a socket can be.
SocketError
This enum describes the socket errors that can occur.
@ ProxyConnectionClosedError
@ ProxyConnectionRefusedError
@ ProxyConnectionTimeoutError
@ UnsupportedSocketOperationError
@ ProxyAuthenticationRequiredError
SocketType
This enum describes the transport layer protocol.
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
The QAuthenticator class provides an authentication object.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
qint64 remainingTime() const noexcept
Returns the remaining time in this QDeadlineTimer object in milliseconds.
The QHostAddress class provides an IP address.
QString toString() const
Returns the address as a string.
virtual QAbstractSocketEngine * createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent) override
~QHttpSocketEnginePrivate()
QHttpSocketEnginePrivate()
QHttpSocketEngine::HttpState state
QHttpNetworkReply * reply
void setWriteNotificationEnabled(bool enable) override
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface) override
bool bind(const QHostAddress &address, quint16 port) override
bool waitForRead(QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
void slotSocketReadNotification()
void slotSocketStateChanged(QAbstractSocket::SocketState state)
bool isWriteNotificationEnabled() const override
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
bool waitForWrite(QDeadlineTimer deadline=QDeadlineTimer{DefaultTimeout}, bool *timedOut=nullptr) override
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface) override
void slotSocketDisconnected()
bool setMulticastInterface(const QNetworkInterface &iface) override
qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *, PacketHeaderOptions) override
void slotSocketBytesWritten()
bool listen(int backlog) override
QHttpSocketEngine(QObject *parent=nullptr)
bool isValid() const override
qint64 write(const char *data, qint64 len) override
bool connectToHostByName(const QString &name, quint16 port) override
qintptr socketDescriptor() const override
void setExceptionNotificationEnabled(bool enable) override
bool hasPendingDatagrams() const override
qint64 bytesToWrite() const override
bool isReadNotificationEnabled() const override
QNetworkInterface multicastInterface() const override
bool setOption(SocketOption option, int value) override
void waitForProtocolHandshake(QDeadlineTimer deadline) const
qint64 bytesAvailable() const override
bool connectToHost(const QHostAddress &address, quint16 port) override
qint64 read(char *data, qint64 maxlen) override
int option(SocketOption option) const override
void setReadNotificationEnabled(bool enable) override
qintptr accept() override
void slotSocketConnected()
void setProxy(const QNetworkProxy &networkProxy)
bool isExceptionNotificationEnabled() const override
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol) override
void slotSocketError(QAbstractSocket::SocketError error)
qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &) override
qint64 pendingDatagramSize() const override
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces.
The QNetworkProxy class provides a network layer proxy.
QString user() const
Returns the user name used for authentication.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
QString password() const
Returns the password used for authentication.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
The QTcpSocket class provides a TCP socket.
static QByteArray toAce(const QString &domain, AceProcessingOptions options={})
Combined button and popup list for selecting options.
DBusConnection const char DBusError * error
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char * method
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
GLenum GLsizei GLuint GLint * bytesWritten
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
GLsizei const GLchar *const * path
QDeadlineTimer deadline(30s)
socketLayer waitForWrite()