50 #if !defined(QT_NO_NETWORKPROXY) && !defined(QT_NO_HTTP) 75 #ifndef QT_NO_BEARERMANAGEMENT 76 d->socket->setProperty(
"_q_networkSession",
property(
"_q_networkSession"));
117 d->authenticator.setUser(user);
120 d->authenticator.setPassword(password);
126 return d->socket ?
d->socket->socketDescriptor() : 0;
139 d->credentialsSent =
false;
143 qWarning(
"QHttpSocketEngine::connectToHost: called when already connected");
155 d->socket->setReadBufferSize(65536);
156 d->socket->connectToHost(
d->proxy.hostName(),
d->proxy.port());
184 d->peerName = hostname;
217 return d->readBuffer.size() + (
d->socket ?
d->socket->bytesAvailable() : 0);
223 qint64 bytesRead =
d->socket->read(data, maxlen);
226 &&
d->socket->bytesAvailable() == 0) {
230 if (bytesRead == -1) {
246 return d->socket->write(data, len);
249 #ifndef QT_NO_UDPSOCKET 250 #ifndef QT_NO_NETWORKINTERFACE 278 #endif // QT_NO_NETWORKINTERFACE 301 #endif // QT_NO_UDPSOCKET 307 return d->socket->bytesToWrite();
350 return timeout < 0 ? 0 : timeout;
364 if (!
d->socket->bytesAvailable()) {
368 setError(
d->socket->error(),
d->socket->errorString());
383 setError(
d->socket->error(),
d->socket->errorString());
397 if (
d->socket->bytesToWrite()) {
398 if (!
d->socket->waitForBytesWritten(msecs)) {
428 bool checkRead,
bool checkWrite,
429 int msecs,
bool *timedOut)
437 *readyToRead = canRead;
444 *readyToWrite = canWrite;
451 return d->readNotificationEnabled;
457 if (
d->readNotificationEnabled == enable)
460 d->readNotificationEnabled = enable;
471 return d->writeNotificationEnabled;
477 d->writeNotificationEnabled = enable;
485 return d->exceptNotificationEnabled;
491 d->exceptNotificationEnabled = enable;
499 const char method[] =
"CONNECT";
501 d->peerAddress.toString().toLatin1() :
507 data +=
" HTTP/1.1\r\n";
508 data +=
"Proxy-Connection: keep-alive\r\n" 514 data +=
"Mozilla/5.0";
516 "Host: " + peerAddress +
"\r\n";
520 d->credentialsSent =
true;
528 d->socket->write(data);
539 if (
d->state !=
Connected &&
d->socket->bytesAvailable() == 0)
544 if (
d->readNotificationEnabled)
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();
564 d->pendingResponseData -=
read;
566 if (
d->pendingResponseData > 0)
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.")) {
586 d->readBuffer.clear();
595 d->readBuffer.clear();
599 if (statusCode == 200) {
604 d->authenticator.detach();
607 }
else if (statusCode == 407) {
608 if (
d->credentialsSent) {
611 d->authenticator.detach();
615 else if (
d->authenticator.isNull())
616 d->authenticator.detach();
634 if (proxyConnectionHeader.
isEmpty())
636 proxyConnectionHeader = proxyConnectionHeader.
toLower();
639 }
else if (proxyConnectionHeader ==
QLatin1String(
"keep-alive")) {
651 d->socket->disconnectFromHost();
652 d->socket->readAll();
660 d->socket->disconnectFromHost();
665 d->socket->connectToHost(
d->proxy.hostName(),
d->proxy.port());
669 if (ok && contentLength > 0) {
671 d->pendingResponseData = contentLength;
672 goto readResponseContent;
683 if (statusCode == 403 || statusCode == 405) {
687 }
else if (statusCode == 404) {
690 }
else if (statusCode == 503) {
707 if (
d->state ==
Connected &&
d->writeNotificationEnabled)
714 d->readBuffer.clear();
727 setError(error,
d->socket->errorString());
737 setError(error,
d->socket->errorString());
739 qDebug() <<
"QHttpSocketEngine::slotSocketError: got weird error =" <<
error;
752 d->readNotificationPending =
false;
753 if (
d->readNotificationEnabled)
760 d->writeNotificationPending =
false;
761 if (
d->writeNotificationEnabled)
768 d->connectionNotificationPending =
false;
775 d->readNotificationActivated =
true;
779 if ((
d->readNotificationEnabled && !
d->readNotificationPending) ||
d->connectionNotificationPending) {
780 d->readNotificationPending =
true;
788 d->writeNotificationActivated =
true;
789 if (
d->writeNotificationEnabled && !
d->writeNotificationPending) {
790 d->writeNotificationPending =
true;
798 if (!
d->connectionNotificationPending) {
799 d->connectionNotificationPending =
true;
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)
836 if (!qobject_cast<QAbstractSocket *>(parent))
The QVariant class acts like a union for the most common Qt data types.
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
qint64 write(const char *data, qint64 len)
void slotSocketReadNotification()
static int qt_timeout_value(int msecs, int elapsed)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
static double elapsed(qint64 after, qint64 before)
#define QT_END_NAMESPACE
This macro expands to.
void setProtocol(QAbstractSocket::NetworkLayerProtocol protocol)
SocketType
This enum describes the transport layer protocol.
qint64 bytesToWrite() const
bool setOption(SocketOption option, int value)
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
void setProxy(const QNetworkProxy &networkProxy)
QHttpSocketEngine::HttpState state
void emitWriteNotification()
void emitPendingWriteNotification()
void setWriteNotificationEnabled(bool enable)
bool hasPendingDatagrams() const
void parseHttpResponse(const QHttpResponseHeader &, bool isProxy)
The QByteArray class provides an array of bytes.
qint64 read(char *data, qint64 maxlen)
void setPeerAddress(const QHostAddress &address)
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void setState(QAbstractSocket::SocketState state)
void slotSocketConnected()
void setLocalPort(quint16 port)
NetworkLayerProtocol
This enum describes the network layer protocol values used in Qt.
The QString class provides a Unicode character string.
bool waitForWrite(int msecs=30000, bool *timedOut=0)
The QObject class is the base class of all Qt objects.
The QElapsedTimer class provides a fast way to calculate elapsed times.
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
void emitReadNotification()
bool connectToHost(const QHostAddress &address, quint16 port)
SocketState
This enum describes the different states in which a socket can be.
Q_CORE_EXPORT void qDebug(const char *,...)
The QNetworkProxy class provides a network layer proxy.
static QByteArray toAce(const QString &)
Returns the ASCII Compatible Encoding of the given domain name domain.
#define QT_BEGIN_NAMESPACE
This macro expands to.
void emitPendingReadNotification()
static QIntfbScreen * connected
void emitConnectionNotification()
void setError(QAbstractSocket::SocketError error, const QString &errorString) const
QHostAddress peerAddress() const
bool initialize(QAbstractSocket::SocketType type, QAbstractSocket::NetworkLayerProtocol protocol=QAbstractSocket::IPv4Protocol)
bool connectToHostByName(const QString &name, quint16 port)
void setExceptionNotificationEnabled(bool enable)
void setPeerPort(quint16 port)
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void setLocalAddress(const QHostAddress &address)
qint64 writeDatagram(const char *data, qint64 len, const QHostAddress &addr, quint16 port)
SocketError
This enum describes the socket errors that can occur.
QNetworkInterface multicastInterface() const
bool waitForReadOrWrite(bool *readyToRead, bool *readyToWrite, bool checkRead, bool checkWrite, int msecs=30000, bool *timedOut=0)
bool isExceptionNotificationEnabled() const
int socketDescriptor() const
Q_CORE_EXPORT void qWarning(const char *,...)
bool setMulticastInterface(const QNetworkInterface &iface)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
The QTcpSocket class provides a TCP socket.
QHttpSocketEngine(QObject *parent=0)
~QHttpSocketEnginePrivate()
bool leaveMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface)
void connectionNotification()
The QAuthenticator class provides an authentication object.
void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator)
bool isReadNotificationEnabled() const
QAbstractSocket::SocketType socketType
bool waitForRead(int msecs=30000, bool *timedOut=0)
void slotSocketBytesWritten()
QHttpSocketEnginePrivate()
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
void slotSocketError(QAbstractSocket::SocketError error)
QAbstractSocket::SocketError error() const
QObject * parent() const
Returns a pointer to the parent object.
QAbstractSocket::NetworkLayerProtocol protocol() const
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
void slotSocketStateChanged(QAbstractSocket::SocketState state)
void setSocketType(QAbstractSocket::SocketType socketType)
virtual QAbstractSocketEngine * createSocketEngine(QAbstractSocket::SocketType socketType, const QNetworkProxy &, QObject *parent)
qint64 readDatagram(char *data, qint64 maxlen, QHostAddress *addr=0, quint16 *port=0)
bool bind(const QHostAddress &address, quint16 port)
QByteArray calculateResponse(const QByteArray &method, const QByteArray &path)
QVariant property(const char *name) const
Returns the value of the object's name property.
int option(SocketOption option) const
QString password() const
Returns the password used for authentication.
qint64 pendingDatagramSize() const
The QNetworkInterface class provides a listing of the host's IP addresses and network interfaces...
bool isWriteNotificationEnabled() const
The QHostAddress class provides an IP address.
void emitPendingConnectionNotification()
QAbstractSocket::SocketState state() const
QString user() const
Returns the user name used for authentication.
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
bool joinMulticastGroup(const QHostAddress &groupAddress, const QNetworkInterface &interface)
void setReadNotificationEnabled(bool enable)
qint64 bytesAvailable() const
void slotSocketDisconnected()
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
void start()
Starts this timer.