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();
324 if (!
d->socket->bytesAvailable()) {
328 setError(
d->socket->error(),
d->socket->errorString());
343 setError(
d->socket->error(),
d->socket->errorString());
357 if (
d->socket->bytesToWrite()) {
358 if (!
d->socket->waitForBytesWritten(msecs)) {
388 bool checkRead,
bool checkWrite,
389 int msecs,
bool *timedOut)
397 *readyToRead = canRead;
404 *readyToWrite = canWrite;
411 return d->readNotificationEnabled;
417 if (
d->readNotificationEnabled ==
enable)
420 d->readNotificationEnabled =
enable;
426 emitReadNotification();
434 return d->writeNotificationEnabled;
440 d->writeNotificationEnabled =
enable;
448 return d->exceptNotificationEnabled;
454 d->exceptNotificationEnabled =
enable;
462 const char method[] =
"CONNECT";
464 d->peerAddress.toString().toLatin1() :
470 data +=
" HTTP/1.1\r\n";
471 data +=
"Proxy-Connection: keep-alive\r\n";
473 if (!
d->proxy.hasRawHeader(
"User-Agent"))
474 data +=
"User-Agent: Mozilla/5.0\r\n";
475 const auto headers =
d->proxy.rawHeaderList();
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();
563 d->authenticator.detach();
565 priv->hasFailed =
true;
568 priv->parseHttpResponse(
d->reply->header(),
true,
d->proxy.hostName());
575 emitConnectionNotification();
580 QByteArray proxyConnectionHeader =
d->reply->headerField(
"Proxy-Connection");
583 if (proxyConnectionHeader.
isEmpty())
584 proxyConnectionHeader =
d->reply->headerField(
"Connection");
593 willClose = (
d->reply->majorVersion() * 0x100 +
d->reply->minorVersion()) <= 0x0100;
599 d->socket->disconnectFromHost();
600 d->socket->readAll();
611 d->socket->disconnectFromHost();
616 d->socket->connectToHost(
d->proxy.hostName(),
d->proxy.port());
626 if (statusCode == 403 || statusCode == 405) {
630 }
else if (statusCode == 404) {
633 }
else if (statusCode == 503) {
644 emitConnectionNotification();
647bool QHttpSocketEngine::readHttpHeader()
657 d->reply->d_func()->clearHttpLayerInformation();
661 ok =
d->reply->d_func()->readStatus(
d->socket) != -1;
666 ok =
d->reply->d_func()->readHeader(
d->socket) != -1;
671 bool contentLengthOk;
672 int contentLength =
d->reply->headerField(
"Content-Length").toInt(&contentLengthOk);
673 if (contentLengthOk && contentLength > 0)
674 d->pendingResponseData = contentLength;
683 if (
d->state ==
Connected &&
d->writeNotificationEnabled)
684 emitWriteNotification();
703 emitConnectionNotification();
714 qDebug() <<
"QHttpSocketEngine::slotSocketError: got weird error =" <<
error;
716 emitReadNotification();
724void QHttpSocketEngine::emitPendingReadNotification()
727 d->readNotificationPending =
false;
728 if (
d->readNotificationEnabled)
732void QHttpSocketEngine::emitPendingWriteNotification()
735 d->writeNotificationPending =
false;
736 if (
d->writeNotificationEnabled)
740void QHttpSocketEngine::emitPendingConnectionNotification()
743 d->connectionNotificationPending =
false;
747void QHttpSocketEngine::emitReadNotification()
753 if ((
d->readNotificationEnabled && !
d->readNotificationPending) ||
d->connectionNotificationPending) {
754 d->readNotificationPending =
true;
759void QHttpSocketEngine::emitWriteNotification()
762 if (
d->writeNotificationEnabled && !
d->writeNotificationPending) {
763 d->writeNotificationPending =
true;
768void QHttpSocketEngine::emitConnectionNotification()
771 if (!
d->connectionNotificationPending) {
772 d->connectionNotificationPending =
true;
778 : readNotificationEnabled(
false)
779 , writeNotificationEnabled(
false)
780 , exceptNotificationEnabled(
false)
781 , readNotificationPending(
false)
782 , writeNotificationPending(
false)
783 , connectionNotificationPending(
false)
784 , credentialsSent(
false)
785 , pendingResponseData(0)
808 if (!qobject_cast<QAbstractSocket *>(
parent))
825#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.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
int compare(QByteArrayView a, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
qint64 elapsed() const noexcept
Returns the number of milliseconds since this QElapsedTimer was last started.
void start() noexcept
Starts this timer.
The QHostAddress class provides an IP address.
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
void slotSocketReadNotification()
void slotSocketStateChanged(QAbstractSocket::SocketState state)
bool isWriteNotificationEnabled() const 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 waitForWrite(int msecs=30000, bool *timedOut=nullptr) 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
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
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=nullptr) override
void slotSocketError(QAbstractSocket::SocketError error)
bool waitForRead(int msecs=30000, bool *timedOut=nullptr) override
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
bool isEmpty() const
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
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static QT_BEGIN_NAMESPACE const char * socketType(QSocketNotifier::Type type)
int qt_subtract_from_timeout(int timeout, int elapsed)
GLenum GLsizei GLuint GLint * bytesWritten
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
GLsizei const GLchar *const * path
socketLayer waitForWrite()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent