Qt 4.8
Public Slots | Signals | Public Functions | Public Variables | Protected Slots | Protected Variables | Static Protected Variables | List of all members
QHttpThreadDelegate Class Reference

#include <qhttpthreaddelegate_p.h>

Inheritance diagram for QHttpThreadDelegate:
QObject

Public Slots

void abortRequest ()
 
void readBufferFreed (qint64 size)
 
void readBufferSizeChanged (qint64 size)
 
void startRequest ()
 
void startRequestSynchronously ()
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void authenticationRequired (const QHttpNetworkRequest &request, QAuthenticator *)
 
void downloadData (QByteArray)
 
void downloadFinished ()
 
void downloadMetaData (QList< QPair< QByteArray, QByteArray > >, int, QString, bool, QSharedPointer< char >, qint64)
 
void downloadProgress (qint64, qint64)
 
void error (QNetworkReply::NetworkError, const QString)
 
void proxyAuthenticationRequired (const QNetworkProxy &, QAuthenticator *)
 
void sslConfigurationChanged (const QSslConfiguration)
 
void sslErrors (const QList< QSslError > &, bool *, QList< QSslError > *)
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

 QHttpThreadDelegate (QObject *parent=0)
 
 ~QHttpThreadDelegate ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Public Variables

QSharedPointer< QNetworkAccessAuthenticationManagerauthenticationManager
 
qint64 bytesEmitted
 
QNetworkProxy cacheProxy
 
qint64 downloadBufferMaximumSize
 
QHttpNetworkRequest httpRequest
 
qint64 incomingContentLength
 
QNetworkReply::NetworkError incomingErrorCode
 
QString incomingErrorDetail
 
QList< QPair< QByteArray, QByteArray > > incomingHeaders
 
QString incomingReasonPhrase
 
QSslConfiguration incomingSslConfiguration
 
int incomingStatusCode
 
bool isPipeliningUsed
 
QSharedPointer< QNetworkSessionnetworkSession
 
QSharedPointer< QAtomicIntpendingDownloadData
 
QSharedPointer< QAtomicIntpendingDownloadProgress
 
qint64 readBufferMaxSize
 
bool ssl
 
bool synchronous
 
QByteArray synchronousDownloadData
 
QNetworkProxy transparentProxy
 

Protected Slots

void cacheCredentialsSlot (const QHttpNetworkRequest &request, QAuthenticator *authenticator)
 
void dataReadProgressSlot (int done, int total)
 
void finishedSlot ()
 
void finishedWithErrorSlot (QNetworkReply::NetworkError errorCode, const QString &detail=QString())
 
void headerChangedSlot ()
 
void readyReadSlot ()
 
void sslErrorsSlot (const QList< QSslError > &errors)
 
void synchronousAuthenticationRequiredSlot (const QHttpNetworkRequest &request, QAuthenticator *)
 
void synchronousFinishedSlot ()
 
void synchronousFinishedWithErrorSlot (QNetworkReply::NetworkError errorCode, const QString &detail=QString())
 
void synchronousHeaderChangedSlot ()
 
void synchronousProxyAuthenticationRequiredSlot (const QNetworkProxy &, QAuthenticator *)
 

Protected Variables

QByteArray cacheKey
 
QSharedPointer< char > downloadBuffer
 
QNetworkAccessCachedHttpConnectionhttpConnection
 
QHttpNetworkReplyhttpReply
 
QEventLoopsynchronousRequestLoop
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 

Static Protected Variables

static QThreadStorage< QNetworkAccessCache * > connections
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Additional Inherited Members

- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Detailed Description

Definition at line 81 of file qhttpthreaddelegate_p.h.

Constructors and Destructors

◆ QHttpThreadDelegate()

QHttpThreadDelegate::QHttpThreadDelegate ( QObject parent = 0)
explicit

Definition at line 193 of file qhttpthreaddelegate.cpp.

193  :
194  QObject(parent)
195  , ssl(false)
197  , readBufferMaxSize(0)
198  , bytesEmitted(0)
201  , synchronous(false)
202  , incomingStatusCode(0)
203  , isPipeliningUsed(false)
206  , downloadBuffer(0)
207  , httpConnection(0)
208  , httpReply(0)
210 {
211 }
QNetworkReply::NetworkError incomingErrorCode
QSharedPointer< char > downloadBuffer
QEventLoop * synchronousRequestLoop
QNetworkAccessCachedHttpConnection * httpConnection
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QSharedPointer< QAtomicInt > pendingDownloadProgress
QHttpNetworkReply * httpReply
QSharedPointer< QAtomicInt > pendingDownloadData

◆ ~QHttpThreadDelegate()

QHttpThreadDelegate::~QHttpThreadDelegate ( )

Definition at line 178 of file qhttpthreaddelegate.cpp.

179 {
180  // It could be that the main thread has asked us to shut down, so we need to delete the HTTP reply
181  if (httpReply) {
182  delete httpReply;
183  }
184 
185  // Get the object cache that stores our QHttpNetworkConnection objects
186  // and release the entry for this QHttpNetworkConnection
189  }
190 }
static QThreadStorage< QNetworkAccessCache * > connections
T & localData()
Returns a reference to the data that was set by the calling thread.
bool hasLocalData() const
If T is a pointer type, returns true if the calling thread has non-zero data available.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
void releaseEntry(const QByteArray &key)
QHttpNetworkReply * httpReply

Functions

◆ abortRequest

void QHttpThreadDelegate::abortRequest ( )
slot

Definition at line 334 of file qhttpthreaddelegate.cpp.

Referenced by startRequestSynchronously().

335 {
336 #ifdef QHTTPTHREADDELEGATE_DEBUG
337  qDebug() << "QHttpThreadDelegate::abortRequest() thread=" << QThread::currentThreadId() << "sync=" << synchronous;
338 #endif
339  if (httpReply) {
340  delete httpReply;
341  httpReply = 0;
342  }
343 
344  // Got aborted by the timeout timer
345  if (synchronous) {
348  } else {
349  //only delete this for asynchronous mode or QNetworkAccessHttpBackend will crash - see QNetworkAccessHttpBackend::postRequest()
350  this->deleteLater();
351  }
352 }
QNetworkReply::NetworkError incomingErrorCode
Q_CORE_EXPORT void qDebug(const char *,...)
QEventLoop * synchronousRequestLoop
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QHttpNetworkReply * httpReply
void deleteLater()
Schedules this object for deletion.
Definition: qobject.cpp:2145
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ authenticationRequired

void QHttpThreadDelegate::authenticationRequired ( const QHttpNetworkRequest request,
QAuthenticator  
)
signal

◆ cacheCredentialsSlot

void QHttpThreadDelegate::cacheCredentialsSlot ( const QHttpNetworkRequest request,
QAuthenticator authenticator 
)
protectedslot

Definition at line 580 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

581 {
582  authenticationManager->cacheCredentials(request.url(), authenticator);
583 }
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
void cacheCredentials(const QUrl &url, const QAuthenticator *auth)

◆ dataReadProgressSlot

void QHttpThreadDelegate::dataReadProgressSlot ( int  done,
int  total 
)
protectedslot

Definition at line 569 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

570 {
571  // If we don't have a download buffer don't attempt to go this codepath
572  // It is not used by QNetworkAccessHttpBackend
573  if (downloadBuffer.isNull())
574  return;
575 
577  emit downloadProgress(done, total);
578 }
QSharedPointer< char > downloadBuffer
void downloadProgress(qint64, qint64)
#define emit
Definition: qobjectdefs.h:76
QSharedPointer< QAtomicInt > pendingDownloadProgress
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.

◆ downloadData

void QHttpThreadDelegate::downloadData ( QByteArray  )
signal

Referenced by finishedSlot(), and readyReadSlot().

◆ downloadFinished

void QHttpThreadDelegate::downloadFinished ( )
signal

◆ downloadMetaData

void QHttpThreadDelegate::downloadMetaData ( QList< QPair< QByteArray, QByteArray > >  ,
int  ,
QString  ,
bool  ,
QSharedPointer< char >  ,
qint64   
)
signal

Referenced by headerChangedSlot().

◆ downloadProgress

void QHttpThreadDelegate::downloadProgress ( qint64  ,
qint64   
)
signal

Referenced by dataReadProgressSlot().

◆ error

void QHttpThreadDelegate::error ( QNetworkReply::NetworkError  ,
const QString   
)
signal

◆ finishedSlot

void QHttpThreadDelegate::finishedSlot ( )
protectedslot

Definition at line 411 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

412 {
413  if (!httpReply)
414  return;
415 
416 #ifdef QHTTPTHREADDELEGATE_DEBUG
417  qDebug() << "QHttpThreadDelegate::finishedSlot() thread=" << QThread::currentThreadId() << "result=" << httpReply->statusCode();
418 #endif
419 
420  // If there is still some data left emit that now
421  while (httpReply->readAnyAvailable()) {
424  }
425 
426 #ifndef QT_NO_OPENSSL
427  if (ssl)
429 #endif
430 
431  if (httpReply->statusCode() >= 400) {
432  // it's an error reply
433  QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply",
434  "Error downloading %1 - server replied: %2"));
437  }
438 
440 
442  QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
443  httpReply = 0;
444 }
static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QString reasonPhrase() const
bool readAnyAvailable() const
QHttpNetworkRequest httpRequest
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
void error(QNetworkReply::NetworkError, const QString)
void sslConfigurationChanged(const QSslConfiguration)
#define emit
Definition: qobjectdefs.h:76
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void downloadData(QByteArray)
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QHttpNetworkReply * httpReply
QSslConfiguration sslConfiguration() const
QSharedPointer< QAtomicInt > pendingDownloadData
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ finishedWithErrorSlot

void QHttpThreadDelegate::finishedWithErrorSlot ( QNetworkReply::NetworkError  errorCode,
const QString detail = QString() 
)
protectedslot

Definition at line 469 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

470 {
471  if (!httpReply)
472  return;
473 
474 #ifdef QHTTPTHREADDELEGATE_DEBUG
475  qDebug() << "QHttpThreadDelegate::finishedWithErrorSlot() thread=" << QThread::currentThreadId() << "error=" << errorCode << detail;
476 #endif
477 
478 #ifndef QT_NO_OPENSSL
479  if (ssl)
481 #endif
482  emit error(errorCode,detail);
484 
485 
487  QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection);
488  httpReply = 0;
489 }
Q_CORE_EXPORT void qDebug(const char *,...)
void error(QNetworkReply::NetworkError, const QString)
void sslConfigurationChanged(const QSslConfiguration)
#define emit
Definition: qobjectdefs.h:76
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QHttpNetworkReply * httpReply
QSslConfiguration sslConfiguration() const
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ headerChangedSlot

void QHttpThreadDelegate::headerChangedSlot ( )
protectedslot

Definition at line 513 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

514 {
515  if (!httpReply)
516  return;
517 
518 #ifdef QHTTPTHREADDELEGATE_DEBUG
519  qDebug() << "QHttpThreadDelegate::headerChangedSlot() thread=" << QThread::currentThreadId();
520 #endif
521 
522 #ifndef QT_NO_OPENSSL
523  if (ssl)
525 #endif
526 
527  // Is using a zerocopy buffer allowed by user and possible with this reply?
529  && downloadBufferMaximumSize > 0) {
530  char *buf = new char[httpReply->contentLength()]; // throws if allocation fails
531  if (buf) {
534  }
535  }
536 
537  // We fetch this into our own
543 
550 }
QSharedPointer< char > downloadBuffer
static void downloadBufferDeleter(char *ptr)
QString reasonPhrase() const
QList< QPair< QByteArray, QByteArray > > header() const
void downloadMetaData(QList< QPair< QByteArray, QByteArray > >, int, QString, bool, QSharedPointer< char >, qint64)
bool isPipeliningUsed() const
bool supportsUserProvidedDownloadBuffer()
Q_CORE_EXPORT void qDebug(const char *,...)
void sslConfigurationChanged(const QSslConfiguration)
#define emit
Definition: qobjectdefs.h:76
qint64 contentLength() const
QList< QPair< QByteArray, QByteArray > > incomingHeaders
void setUserProvidedDownloadBuffer(char *)
QHttpNetworkReply * httpReply
QSslConfiguration sslConfiguration() const
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ proxyAuthenticationRequired

void QHttpThreadDelegate::proxyAuthenticationRequired ( const QNetworkProxy ,
QAuthenticator  
)
signal

◆ readBufferFreed

void QHttpThreadDelegate::readBufferFreed ( qint64  size)
slot

Definition at line 366 of file qhttpthreaddelegate.cpp.

367 {
368  if (readBufferMaxSize) {
369  bytesEmitted -= size;
370 
371  QMetaObject::invokeMethod(this, "readyReadSlot", Qt::QueuedConnection);
372  }
373 }
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ readBufferSizeChanged

void QHttpThreadDelegate::readBufferSizeChanged ( qint64  size)
slot

Definition at line 354 of file qhttpthreaddelegate.cpp.

355 {
356 #ifdef QHTTPTHREADDELEGATE_DEBUG
357  qDebug() << "QHttpThreadDelegate::readBufferSizeChanged() size " << size;
358 #endif
359  if (httpReply) {
362  readBufferMaxSize = size;
363  }
364 }
void setDownstreamLimited(bool t)
Q_CORE_EXPORT void qDebug(const char *,...)
void setReadBufferSize(qint64 size)
QHttpNetworkReply * httpReply

◆ readyReadSlot

void QHttpThreadDelegate::readyReadSlot ( )
protectedslot

Definition at line 375 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

376 {
377  if (!httpReply)
378  return;
379 
380  // Don't do in zerocopy case
381  if (!downloadBuffer.isNull())
382  return;
383 
384  if (readBufferMaxSize) {
386  qint64 sizeEmitted = 0;
387  while (httpReply->readAnyAvailable() && (sizeEmitted < (readBufferMaxSize-bytesEmitted))) {
389  sizeEmitted = readBufferMaxSize-bytesEmitted;
390  bytesEmitted += sizeEmitted;
392  emit downloadData(httpReply->read(sizeEmitted));
393  } else {
394  sizeEmitted = httpReply->sizeNextBlock();
395  bytesEmitted += sizeEmitted;
398  }
399  }
400  } else {
401  // We need to wait until we empty data from the read buffer in the reply.
402  }
403  } else {
404  while (httpReply->readAnyAvailable()) {
407  }
408  }
409 }
QSharedPointer< char > downloadBuffer
bool readAnyAvailable() const
QByteArray read(qint64 amount)
#define emit
Definition: qobjectdefs.h:76
__int64 qint64
Definition: qglobal.h:942
void downloadData(QByteArray)
QHttpNetworkReply * httpReply
bool isNull() const
Returns true if this object is holding a reference to a null pointer.
QSharedPointer< QAtomicInt > pendingDownloadData
int fetchAndAddRelease(int valueToAdd)
Atomic fetch-and-add.

◆ sslConfigurationChanged

void QHttpThreadDelegate::sslConfigurationChanged ( const QSslConfiguration  )
signal

◆ sslErrors

void QHttpThreadDelegate::sslErrors ( const QList< QSslError > &  ,
bool *  ,
QList< QSslError > *   
)
signal

Referenced by sslErrorsSlot(), and startRequest().

◆ sslErrorsSlot

void QHttpThreadDelegate::sslErrorsSlot ( const QList< QSslError > &  errors)
protectedslot

Definition at line 587 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

588 {
589  if (!httpReply)
590  return;
591 
593 
594  bool ignoreAll = false;
595  QList<QSslError> specificErrors;
596  emit sslErrors(errors, &ignoreAll, &specificErrors);
597  if (ignoreAll)
599  if (!specificErrors.isEmpty())
600  httpReply->ignoreSslErrors(specificErrors);
601 }
void sslErrors(const QList< QSslError > &, bool *, QList< QSslError > *)
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void sslConfigurationChanged(const QSslConfiguration)
#define emit
Definition: qobjectdefs.h:76
QHttpNetworkReply * httpReply
QSslConfiguration sslConfiguration() const

◆ startRequest

void QHttpThreadDelegate::startRequest ( )
slot

Definition at line 240 of file qhttpthreaddelegate.cpp.

241 {
242 #ifdef QHTTPTHREADDELEGATE_DEBUG
243  qDebug() << "QHttpThreadDelegate::startRequest() thread=" << QThread::currentThreadId();
244 #endif
245  // Check QThreadStorage for the QNetworkAccessCache
246  // If not there, create this connection cache
247  if (!connections.hasLocalData()) {
249  }
250 
251  // check if we have an open connection to this host
252  QUrl urlCopy = httpRequest.url();
253  urlCopy.setPort(urlCopy.port(ssl ? 443 : 80));
254 
255 #ifndef QT_NO_NETWORKPROXY
258  else if (cacheProxy.type() != QNetworkProxy::NoProxy)
259  cacheKey = makeCacheKey(urlCopy, &cacheProxy);
260  else
261 #endif
262  cacheKey = makeCacheKey(urlCopy, 0);
263 
264 
265  // the http object is actually a QHttpNetworkConnection
267  if (httpConnection == 0) {
268  // no entry in cache; create an object
269  // the http object is actually a QHttpNetworkConnection
270 #ifdef QT_NO_BEARERMANAGEMENT
271  httpConnection = new QNetworkAccessCachedHttpConnection(urlCopy.host(), urlCopy.port(), ssl);
272 #else
274 #endif
275 #ifndef QT_NO_OPENSSL
276  // Set the QSslConfiguration from this QNetworkRequest.
279  }
280 #endif
281 
282 #ifndef QT_NO_NETWORKPROXY
283  httpConnection->setTransparentProxy(transparentProxy);
284  httpConnection->setCacheProxy(cacheProxy);
285 #endif
286 
287  // cache the QHttpNetworkConnection corresponding to this cache key
288  connections.localData()->addEntry(cacheKey, httpConnection);
289  }
290 
291 
292  // Send the request to the connection
293  httpReply = httpConnection->sendRequest(httpRequest);
294  httpReply->setParent(this);
295 
296  // Connect the reply signals that we need to handle and then forward
297  if (synchronous) {
298  connect(httpReply,SIGNAL(headerChanged()), this, SLOT(synchronousHeaderChangedSlot()));
299  connect(httpReply,SIGNAL(finished()), this, SLOT(synchronousFinishedSlot()));
300  connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError, const QString)),
302 
307 
308  // Don't care about ignored SSL errors for now in the synchronous HTTP case.
309  } else if (!synchronous) {
310  connect(httpReply,SIGNAL(headerChanged()), this, SLOT(headerChangedSlot()));
311  connect(httpReply,SIGNAL(finished()), this, SLOT(finishedSlot()));
312  connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError, const QString)),
314  // some signals are only interesting when normal asynchronous style is used
315  connect(httpReply,SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
316  connect(httpReply,SIGNAL(dataReadProgress(int, int)), this, SLOT(dataReadProgressSlot(int,int)));
317 #ifndef QT_NO_OPENSSL
319 #endif
320 
321  // In the asynchronous HTTP case we can just forward those signals
322  // Connect the reply signals that we can directly forward
327  }
328 
331 }
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
static QThreadStorage< QNetworkAccessCache * > connections
void synchronousFinishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail=QString())
#define SLOT(a)
Definition: qobjectdefs.h:226
QHttpNetworkRequest httpRequest
QSslConfiguration incomingSslConfiguration
NetworkError
Indicates all possible error conditions found during the processing of the request.
Definition: qnetworkreply.h:70
void setTransparentProxy(const QNetworkProxy &networkProxy)
void dataReadProgressSlot(int done, int total)
CacheableObject * requestEntryNow(const QByteArray &key)
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString host() const
Returns the host of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4837
void sslErrors(const QList< QSslError > &, bool *, QList< QSslError > *)
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
void setCacheProxy(const QNetworkProxy &networkProxy)
Q_CORE_EXPORT void qDebug(const char *,...)
int port() const
Returns the port of the URL, or -1 if the port is unspecified.
Definition: qurl.cpp:4916
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QNetworkProxy class provides a network layer proxy.
void addEntry(const QByteArray &key, CacheableObject *entry)
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...
Definition: qobject.cpp:2580
T & localData()
Returns a reference to the data that was set by the calling thread.
static QSslConfiguration defaultConfiguration()
Returns the default SSL configuration to be used in new SSL connections.
QNetworkAccessCachedHttpConnection * httpConnection
The QAuthenticator class provides an authentication object.
static QByteArray makeCacheKey(QUrl &url, QNetworkProxy *proxy)
bool hasLocalData() const
If T is a pointer type, returns true if the calling thread has non-zero data available.
void setPort(int port)
Sets the port of the URL to port.
Definition: qurl.cpp:4897
void setLocalData(T t)
Sets the local data for the calling thread to data.
QSharedPointer< QNetworkSession > networkSession
void finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail=QString())
void synchronousProxyAuthenticationRequiredSlot(const QNetworkProxy &, QAuthenticator *)
void setSslConfiguration(const QSslConfiguration &config)
QHttpNetworkReply * sendRequest(const QHttpNetworkRequest &request)
void authenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *)
void synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *)
void cacheCredentialsSlot(const QHttpNetworkRequest &request, QAuthenticator *authenticator)
QHttpNetworkReply * httpReply
void sslErrorsSlot(const QList< QSslError > &errors)
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ startRequestSynchronously

void QHttpThreadDelegate::startRequestSynchronously ( )
slot

Definition at line 214 of file qhttpthreaddelegate.cpp.

215 {
216 #ifdef QHTTPTHREADDELEGATE_DEBUG
217  qDebug() << "QHttpThreadDelegate::startRequestSynchronously() thread=" << QThread::currentThreadId();
218 #endif
219  synchronous = true;
220 
222  this->synchronousRequestLoop = &synchronousRequestLoop;
223 
224  // Worst case timeout
225  QTimer::singleShot(30*1000, this, SLOT(abortRequest()));
226 
227  QMetaObject::invokeMethod(this, "startRequest", Qt::QueuedConnection);
228  synchronousRequestLoop.exec();
229 
232 
233 #ifdef QHTTPTHREADDELEGATE_DEBUG
234  qDebug() << "QHttpThreadDelegate::startRequestSynchronously() thread=" << QThread::currentThreadId() << "finished";
235 #endif
236 }
static QThreadStorage< QNetworkAccessCache * > connections
#define SLOT(a)
Definition: qobjectdefs.h:226
Q_CORE_EXPORT void qDebug(const char *,...)
The QEventLoop class provides a means of entering and leaving an event loop.
Definition: qeventloop.h:55
QEventLoop * synchronousRequestLoop
T & localData()
Returns a reference to the data that was set by the calling thread.
void setLocalData(T t)
Sets the local data for the calling thread to data.
bool singleShot
This static function calls a slot after a given time interval.
Definition: qtimer.h:59
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
void releaseEntry(const QByteArray &key)
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
Definition: qeventloop.cpp:181
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ synchronousAuthenticationRequiredSlot

void QHttpThreadDelegate::synchronousAuthenticationRequiredSlot ( const QHttpNetworkRequest request,
QAuthenticator a 
)
protectedslot

Definition at line 604 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

605 {
606  if (!httpReply)
607  return;
608 
609  Q_UNUSED(request);
610 #ifdef QHTTPTHREADDELEGATE_DEBUG
611  qDebug() << "QHttpThreadDelegate::synchronousAuthenticationRequiredSlot() thread=" << QThread::currentThreadId();
612 #endif
613 
614  // Ask the credential cache
616  if (!credential.isNull()) {
617  a->setUser(credential.user);
618  a->setPassword(credential.password);
619  }
620 
621  // Disconnect this connection now since we only want to ask the authentication cache once.
624 }
#define SLOT(a)
Definition: qobjectdefs.h:226
QHttpNetworkRequest httpRequest
long ASN1_INTEGER_get ASN1_INTEGER * a
void setUser(const QString &user)
Sets the user used for authentication.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
QNetworkAuthenticationCredential fetchCachedCredentials(const QUrl &url, const QAuthenticator *auth=0)
Fetch the credential data from the credential cache.
The QAuthenticator class provides an authentication object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
void setPassword(const QString &password)
Sets the password used for authentication.
void authenticationRequired(const QHttpNetworkRequest &request, QAuthenticator *)
void synchronousAuthenticationRequiredSlot(const QHttpNetworkRequest &request, QAuthenticator *)
QHttpNetworkReply * httpReply
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ synchronousFinishedSlot

void QHttpThreadDelegate::synchronousFinishedSlot ( )
protectedslot

Definition at line 446 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

447 {
448  if (!httpReply)
449  return;
450 
451 #ifdef QHTTPTHREADDELEGATE_DEBUG
452  qDebug() << "QHttpThreadDelegate::synchronousFinishedSlot() thread=" << QThread::currentThreadId() << "result=" << httpReply->statusCode();
453 #endif
454  if (httpReply->statusCode() >= 400) {
455  // it's an error reply
456  QString msg = QLatin1String(QT_TRANSLATE_NOOP("QNetworkReply",
457  "Error downloading %1 - server replied: %2"));
460  }
461 
463 
466  httpReply = 0;
467 }
QNetworkReply::NetworkError incomingErrorCode
static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url)
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QString reasonPhrase() const
QHttpNetworkRequest httpRequest
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qDebug(const char *,...)
QEventLoop * synchronousRequestLoop
QByteArray toEncoded(FormattingOptions options=None) const
Returns the encoded representation of the URL if it&#39;s valid; otherwise an empty QByteArray is returne...
Definition: qurl.cpp:5949
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QHttpNetworkReply * httpReply
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ synchronousFinishedWithErrorSlot

void QHttpThreadDelegate::synchronousFinishedWithErrorSlot ( QNetworkReply::NetworkError  errorCode,
const QString detail = QString() 
)
protectedslot

Definition at line 492 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

493 {
494  if (!httpReply)
495  return;
496 
497 #ifdef QHTTPTHREADDELEGATE_DEBUG
498  qDebug() << "QHttpThreadDelegate::synchronousFinishedWithErrorSlot() thread=" << QThread::currentThreadId() << "error=" << errorCode << detail;
499 #endif
500  incomingErrorCode = errorCode;
501  incomingErrorDetail = detail;
502 
505  httpReply = 0;
506 }
QNetworkReply::NetworkError incomingErrorCode
Q_CORE_EXPORT void qDebug(const char *,...)
QEventLoop * synchronousRequestLoop
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
QHttpNetworkReply * httpReply
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ synchronousHeaderChangedSlot

void QHttpThreadDelegate::synchronousHeaderChangedSlot ( )
protectedslot

Definition at line 552 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

553 {
554  if (!httpReply)
555  return;
556 
557 #ifdef QHTTPTHREADDELEGATE_DEBUG
558  qDebug() << "QHttpThreadDelegate::synchronousHeaderChangedSlot() thread=" << QThread::currentThreadId();
559 #endif
560  // Store the information we need in this object, the QNetworkAccessHttpBackend will later read it
566 }
QString reasonPhrase() const
QList< QPair< QByteArray, QByteArray > > header() const
bool isPipeliningUsed() const
Q_CORE_EXPORT void qDebug(const char *,...)
qint64 contentLength() const
QList< QPair< QByteArray, QByteArray > > incomingHeaders
QHttpNetworkReply * httpReply
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

◆ synchronousProxyAuthenticationRequiredSlot

void QHttpThreadDelegate::synchronousProxyAuthenticationRequiredSlot ( const QNetworkProxy p,
QAuthenticator a 
)
protectedslot

Definition at line 627 of file qhttpthreaddelegate.cpp.

Referenced by startRequest().

628 {
629  if (!httpReply)
630  return;
631 
632 #ifdef QHTTPTHREADDELEGATE_DEBUG
633  qDebug() << "QHttpThreadDelegate::synchronousProxyAuthenticationRequiredSlot() thread=" << QThread::currentThreadId();
634 #endif
635  // Ask the credential cache
637  if (!credential.isNull()) {
638  a->setUser(credential.user);
639  a->setPassword(credential.password);
640  }
641 
642  // Disconnect this connection now since we only want to ask the authentication cache once.
645 }
#define SLOT(a)
Definition: qobjectdefs.h:226
void proxyAuthenticationRequired(const QNetworkProxy &, QAuthenticator *)
void setUser(const QString &user)
Sets the user used for authentication.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QNetworkProxy class provides a network layer proxy.
The QAuthenticator class provides an authentication object.
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
void synchronousProxyAuthenticationRequiredSlot(const QNetworkProxy &, QAuthenticator *)
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
void setPassword(const QString &password)
Sets the password used for authentication.
QNetworkAuthenticationCredential fetchCachedProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth=0)
QHttpNetworkReply * httpReply
static Qt::HANDLE currentThreadId()
Returns the thread handle of the currently executing thread.

Properties

◆ authenticationManager

QSharedPointer<QNetworkAccessAuthenticationManager> QHttpThreadDelegate::authenticationManager

◆ bytesEmitted

qint64 QHttpThreadDelegate::bytesEmitted

Definition at line 97 of file qhttpthreaddelegate_p.h.

Referenced by readBufferFreed(), and readyReadSlot().

◆ cacheKey

QByteArray QHttpThreadDelegate::cacheKey
protected

Definition at line 126 of file qhttpthreaddelegate_p.h.

Referenced by startRequest(), and startRequestSynchronously().

◆ cacheProxy

QNetworkProxy QHttpThreadDelegate::cacheProxy

◆ connections

QThreadStorage< QNetworkAccessCache * > QHttpThreadDelegate::connections
staticprotected

◆ downloadBuffer

QSharedPointer<char> QHttpThreadDelegate::downloadBuffer
protected

Definition at line 123 of file qhttpthreaddelegate_p.h.

Referenced by dataReadProgressSlot(), headerChangedSlot(), and readyReadSlot().

◆ downloadBufferMaximumSize

qint64 QHttpThreadDelegate::downloadBufferMaximumSize

◆ httpConnection

QNetworkAccessCachedHttpConnection* QHttpThreadDelegate::httpConnection
protected

Definition at line 125 of file qhttpthreaddelegate_p.h.

Referenced by startRequest().

◆ httpReply

QHttpNetworkReply* QHttpThreadDelegate::httpReply
protected

◆ httpRequest

QHttpNetworkRequest QHttpThreadDelegate::httpRequest

◆ incomingContentLength

qint64 QHttpThreadDelegate::incomingContentLength

◆ incomingErrorCode

QNetworkReply::NetworkError QHttpThreadDelegate::incomingErrorCode

◆ incomingErrorDetail

QString QHttpThreadDelegate::incomingErrorDetail

◆ incomingHeaders

QList<QPair<QByteArray,QByteArray> > QHttpThreadDelegate::incomingHeaders

◆ incomingReasonPhrase

QString QHttpThreadDelegate::incomingReasonPhrase

◆ incomingSslConfiguration

QSslConfiguration QHttpThreadDelegate::incomingSslConfiguration

Definition at line 92 of file qhttpthreaddelegate_p.h.

Referenced by QNetworkAccessHttpBackend::postRequest(), and startRequest().

◆ incomingStatusCode

int QHttpThreadDelegate::incomingStatusCode

◆ isPipeliningUsed

bool QHttpThreadDelegate::isPipeliningUsed

◆ networkSession

QSharedPointer<QNetworkSession> QHttpThreadDelegate::networkSession

◆ pendingDownloadData

QSharedPointer<QAtomicInt> QHttpThreadDelegate::pendingDownloadData

◆ pendingDownloadProgress

QSharedPointer<QAtomicInt> QHttpThreadDelegate::pendingDownloadProgress

◆ readBufferMaxSize

qint64 QHttpThreadDelegate::readBufferMaxSize

Definition at line 96 of file qhttpthreaddelegate_p.h.

Referenced by readBufferFreed(), readBufferSizeChanged(), and readyReadSlot().

◆ ssl

bool QHttpThreadDelegate::ssl

◆ synchronous

bool QHttpThreadDelegate::synchronous

◆ synchronousDownloadData

QByteArray QHttpThreadDelegate::synchronousDownloadData

◆ synchronousRequestLoop

QEventLoop* QHttpThreadDelegate::synchronousRequestLoop
protected

◆ transparentProxy

QNetworkProxy QHttpThreadDelegate::transparentProxy

The documentation for this class was generated from the following files: