Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QNetworkAccessManagerPrivate Class Reference

#include <qnetworkaccessmanager_p.h>

Inheritance diagram for QNetworkAccessManagerPrivate:
QObjectPrivate QObjectData

Public Functions

void _q_networkSessionClosed ()
 
void _q_networkSessionNewConfigurationActivated ()
 
void _q_networkSessionPreferredConfigurationChanged (const QNetworkConfiguration &config, bool isSeamless)
 
void _q_networkSessionStateChanged (QNetworkSession::State state)
 
void _q_replyFinished ()
 
void _q_replySslErrors (const QList< QSslError > &errors)
 
void authenticationRequired (QNetworkAccessBackend *backend, QAuthenticator *authenticator)
 
void cacheCredentials (const QUrl &url, const QAuthenticator *auth)
 
void cacheProxyCredentials (const QNetworkProxy &proxy, const QAuthenticator *auth)
 
void createCookieJar () const
 
void createSession (const QNetworkConfiguration &config)
 
QNetworkAuthenticationCredentialfetchCachedCredentials (const QUrl &url, const QAuthenticator *auth=0)
 
QNetworkAuthenticationCredentialfetchCachedProxyCredentials (const QNetworkProxy &proxy, const QAuthenticator *auth=0)
 
QNetworkAccessBackendfindBackend (QNetworkAccessManager::Operation op, const QNetworkRequest &request)
 
QSharedPointer< QNetworkSessiongetNetworkSession () const
 
QNetworkReplypostProcess (QNetworkReply *reply)
 
QNetworkRequest prepareMultipart (const QNetworkRequest &request, QHttpMultiPart *multiPart)
 
void proxyAuthenticationRequired (QNetworkAccessBackend *backend, const QNetworkProxy &proxy, QAuthenticator *authenticator)
 
 QNetworkAccessManagerPrivate ()
 
QList< QNetworkProxyqueryProxy (const QNetworkProxyQuery &query)
 
 ~QNetworkAccessManagerPrivate ()
 
- Public Functions inherited from QObjectPrivate
void _q_reregisterTimers (void *pointer)
 
void addConnection (int signal, Connection *c)
 
void cleanConnectionLists ()
 
void connectNotify (const char *signal)
 
void deleteChildren ()
 
void disconnectNotify (const char *signal)
 
bool isSender (const QObject *receiver, const char *signal) const
 
bool isSignalConnected (uint signalIdx) const
 Returns true if the signal with index signal_index from object sender is connected. More...
 
void moveToThread_helper ()
 
 QObjectPrivate (int version=QObjectPrivateVersion)
 
QObjectList receiverList (const char *signal) const
 
QObjectList senderList () const
 
void setParent_helper (QObject *)
 
void setThreadData_helper (QThreadData *currentData, QThreadData *targetData)
 
int signalIndex (const char *signalName) const
 Returns the signal index used in the internal connectionLists vector. More...
 
virtual ~QObjectPrivate ()
 
- Public Functions inherited from QObjectData
virtual ~QObjectData ()=0
 

Static Public Functions

static Q_AUTOTEST_EXPORT void clearCache (QNetworkAccessManager *manager)
 
static QNetworkAccessCachegetObjectCache (QNetworkAccessBackend *backend)
 
- Static Public Functions inherited from QObjectPrivate
static void clearGuards (QObject *)
 
static QObjectPrivateget (QObject *o)
 
static void resetCurrentSender (QObject *receiver, Sender *currentSender, Sender *previousSender)
 
static SendersetCurrentSender (QObject *receiver, Sender *sender)
 
static void signalSignature (const QMetaMethod &signal, QVarLengthArray< char > *result)
 

Public Variables

int activeReplyCount
 
QSharedPointer< QNetworkAccessAuthenticationManagerauthenticationManager
 
QNetworkCookieJarcookieJar
 
bool cookieJarCreated
 
QThreadhttpThread
 
bool initializeSession
 
QNetworkSession::State lastSessionState
 
QNetworkAccessManager::NetworkAccessibility networkAccessible
 
QAbstractNetworkCachenetworkCache
 
QString networkConfiguration
 
QSharedPointer< QNetworkSessionnetworkSessionStrongRef
 
QWeakPointer< QNetworkSessionnetworkSessionWeakRef
 
QNetworkAccessCache objectCache
 
bool online
 
QNetworkProxy proxy
 
QNetworkProxyFactoryproxyFactory
 
- Public Variables inherited from QObjectPrivate
union {
   QObject *   currentChildBeingDeleted
 
   QAbstractDeclarativeData *   declarativeData
 
}; 
 
quint32 connectedSignals [2]
 
QObjectConnectionListVectorconnectionLists
 
SendercurrentSender
 
QList< QPointer< QObject > > eventFilters
 
ExtraDataextraData
 
QString objectName
 
Connectionsenders
 
QAtomicPointer< QtSharedPointer::ExternalRefCountData > sharedRefcount
 
QThreadDatathreadData
 
void * unused
 
- Public Variables inherited from QObjectData
uint blockSig: 1
 
QObjectList children
 
uint hasGuards: 1
 
uint inEventHandler: 1
 
uint inThreadChangeEvent: 1
 
uint isWidget: 1
 
QMetaObjectmetaObject
 
uint ownObjectName: 1
 
QObjectparent
 
uint pendTimer: 1
 
int postedEvents
 
QObjectq_ptr
 
uint receiveChildEvents: 1
 
uint sendChildEvents: 1
 
uint unused: 22
 
uint wasDeleted: 1
 

Additional Inherited Members

- Public Types inherited from QObjectPrivate
typedef void(* StaticMetaCallFunction) (QObject *, QMetaObject::Call, int, void **)
 

Detailed Description

Definition at line 71 of file qnetworkaccessmanager_p.h.

Constructors and Destructors

◆ QNetworkAccessManagerPrivate()

QNetworkAccessManagerPrivate::QNetworkAccessManagerPrivate ( )
inline

Definition at line 74 of file qnetworkaccessmanager_p.h.

75  : networkCache(0), cookieJar(0),
76  httpThread(0),
77 #ifndef QT_NO_NETWORKPROXY
78  proxyFactory(0),
79 #endif
80 #ifndef QT_NO_BEARERMANAGEMENT
84  online(false),
85  initializeSession(true),
86 #endif
87  cookieJarCreated(false),
89  { }
QNetworkAccessManager::NetworkAccessibility networkAccessible
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
QNetworkSession::State lastSessionState
QAbstractNetworkCache * networkCache

◆ ~QNetworkAccessManagerPrivate()

QNetworkAccessManagerPrivate::~QNetworkAccessManagerPrivate ( )

Definition at line 1236 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1237 {
1238  if (httpThread) {
1239  // The thread will deleteLater() itself from its finished() signal
1240  httpThread->quit();
1241  httpThread->wait(5000);
1242  httpThread = 0;
1243  }
1244 }
void quit()
Tells the thread&#39;s event loop to exit with return code 0 (success).
Definition: qthread.cpp:614
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:

Functions

◆ _q_networkSessionClosed()

void QNetworkAccessManagerPrivate::_q_networkSessionClosed ( )

Definition at line 1296 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1297 {
1300  if (networkSession) {
1301  networkConfiguration = networkSession->configuration().identifier();
1302 
1303  //disconnect from old session
1304  QObject::disconnect(networkSession.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
1305  QObject::disconnect(networkSession.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()));
1306  QObject::disconnect(networkSession.data(), SIGNAL(stateChanged(QNetworkSession::State)),
1310  }
1311 }
#define SLOT(a)
Definition: qobjectdefs.h:226
State
This enum describes the connectivity state of the session.
QWeakPointer< QNetworkSession > networkSessionWeakRef
QSharedPointer< QNetworkSession > getNetworkSession() const
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QNetworkAccessManager class allows the application to send network requests and receive replies...
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 clear()
Clears this QWeakPointer object, dropping the reference that it may have had to the pointer...
void clear()
Clears this QSharedPointer object, dropping the reference that it may have had to the pointer...
void _q_networkSessionStateChanged(QNetworkSession::State state)
QSharedPointer< QNetworkSession > networkSessionStrongRef

◆ _q_networkSessionNewConfigurationActivated()

void QNetworkAccessManagerPrivate::_q_networkSessionNewConfigurationActivated ( )

◆ _q_networkSessionPreferredConfigurationChanged()

void QNetworkAccessManagerPrivate::_q_networkSessionPreferredConfigurationChanged ( const QNetworkConfiguration config,
bool  isSeamless 
)

◆ _q_networkSessionStateChanged()

void QNetworkAccessManagerPrivate::_q_networkSessionStateChanged ( QNetworkSession::State  state)

Definition at line 1313 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1314 {
1316 
1317  //Do not emit the networkSessionConnected signal here, except for roaming -> connected
1318  //transition, otherwise it is emitted twice in a row when opening a connection.
1320  emit q->networkSessionConnected();
1321  lastSessionState = state;
1322 
1323  if (online) {
1324  if (state != QNetworkSession::Connected && state != QNetworkSession::Roaming) {
1325  online = false;
1326  emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
1327  }
1328  } else {
1329  if (state == QNetworkSession::Connected || state == QNetworkSession::Roaming) {
1330  online = true;
1331  emit q->networkAccessibleChanged(networkAccessible);
1332  }
1333  }
1334 }
#define Q_Q(Class)
Definition: qglobal.h:2483
QNetworkAccessManager::NetworkAccessibility networkAccessible
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QNetworkSession::State lastSessionState

◆ _q_replyFinished()

void QNetworkAccessManagerPrivate::_q_replyFinished ( )

Definition at line 1075 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1076 {
1078 
1079  QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
1080  if (reply)
1081  emit q->finished(reply);
1082 
1083 #ifndef QT_NO_BEARERMANAGEMENT
1084  // If there are no active requests, release our reference to the network session.
1085  // It will not be destroyed immediately, but rather when the connection cache is flushed
1086  // after 2 minutes.
1087  activeReplyCount--;
1090 #endif
1091 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
void clear()
Clears this QSharedPointer object, dropping the reference that it may have had to the pointer...
QSharedPointer< QNetworkSession > networkSessionStrongRef

◆ _q_replySslErrors()

void QNetworkAccessManagerPrivate::_q_replySslErrors ( const QList< QSslError > &  errors)

Definition at line 1093 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1094 {
1095 #ifndef QT_NO_OPENSSL
1097  QNetworkReply *reply = qobject_cast<QNetworkReply *>(q->sender());
1098  if (reply)
1099  emit q->sslErrors(reply, errors);
1100 #else
1101  Q_UNUSED(errors);
1102 #endif
1103 }
T qobject_cast(QObject *object)
Definition: qobject.h:375
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition: qnetworkreply.h:65
#define Q_Q(Class)
Definition: qglobal.h:2483
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
#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

◆ authenticationRequired()

void QNetworkAccessManagerPrivate::authenticationRequired ( QNetworkAccessBackend backend,
QAuthenticator authenticator 
)

Definition at line 1132 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessBackend::authenticationRequired(), and QNetworkAccessManagerPrivate().

1134 {
1136 
1137  // FIXME: Add support for domains (i.e., the leading path)
1138  QUrl url = backend->reply->url;
1139 
1140  // don't try the cache for the same URL twice in a row
1141  // being called twice for the same URL means the authentication failed
1142  // also called when last URL is empty, e.g. on first call
1143  if ((static_cast<QNetworkRequest::LoadControl>
1145  && (backend->reply->urlForLastAuthentication.isEmpty()
1146  || url != backend->reply->urlForLastAuthentication)) {
1147  // if credentials are included in the url, then use them
1148  if (!url.userName().isEmpty()
1149  && !url.password().isEmpty()) {
1150  authenticator->setUser(url.userName());
1151  authenticator->setPassword(url.password());
1152  backend->reply->urlForLastAuthentication = url;
1153  authenticationManager->cacheCredentials(url, authenticator);
1154  return;
1155  }
1156 
1158  if (!cred.isNull()) {
1159  authenticator->setUser(cred.user);
1160  authenticator->setPassword(cred.password);
1161  backend->reply->urlForLastAuthentication = url;
1162  return;
1163  }
1164  }
1165 
1166  // if we emit a signal here in synchronous mode, the user might spin
1167  // an event loop, which might recurse and lead to problems
1168  if (backend->isSynchronous())
1169  return;
1170 
1171  backend->reply->urlForLastAuthentication = url;
1172  emit q->authenticationRequired(backend->reply->q_func(), authenticator);
1173  authenticationManager->cacheCredentials(url, authenticator);
1174 }
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
Definition: qurl.cpp:4317
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
void setUser(const QString &user)
Sets the user used for authentication.
#define Q_Q(Class)
Definition: qglobal.h:2483
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
QNetworkAuthenticationCredential fetchCachedCredentials(const QUrl &url, const QAuthenticator *auth=0)
Fetch the credential data from the credential cache.
QNetworkReplyImplPrivate * reply
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
QString userName() const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4667
QNetworkRequest request() const
void cacheCredentials(const QUrl &url, const QAuthenticator *auth)
void setPassword(const QString &password)
Sets the password used for authentication.
QString password() const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
Definition: qurl.cpp:4754

◆ cacheCredentials()

void QNetworkAccessManagerPrivate::cacheCredentials ( const QUrl url,
const QAuthenticator auth 
)

◆ cacheProxyCredentials()

void QNetworkAccessManagerPrivate::cacheProxyCredentials ( const QNetworkProxy proxy,
const QAuthenticator auth 
)

◆ clearCache()

void QNetworkAccessManagerPrivate::clearCache ( QNetworkAccessManager manager)
static

Definition at line 1223 of file qnetworkaccessmanager.cpp.

Referenced by getObjectCache().

1224 {
1225  manager->d_func()->objectCache.clear();
1226  manager->d_func()->authenticationManager->clearCache();
1227 
1228  if (manager->d_func()->httpThread) {
1229  // The thread will deleteLater() itself from its finished() signal
1230  manager->d_func()->httpThread->quit();
1231  manager->d_func()->httpThread->wait(5000);
1232  manager->d_func()->httpThread = 0;
1233  }
1234 }

◆ createCookieJar()

void QNetworkAccessManagerPrivate::createCookieJar ( ) const

Definition at line 1122 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1123 {
1124  if (!cookieJarCreated) {
1125  // keep the ugly hack in here
1126  QNetworkAccessManagerPrivate *that = const_cast<QNetworkAccessManagerPrivate *>(this);
1127  that->cookieJar = new QNetworkCookieJar(that->q_func());
1128  that->cookieJarCreated = true;
1129  }
1130 }
The QNetworkCookieJar class implements a simple jar of QNetworkCookie objects.

◆ createSession()

void QNetworkAccessManagerPrivate::createSession ( const QNetworkConfiguration config)

Definition at line 1247 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1248 {
1250 
1251  initializeSession = false;
1252 
1253  //resurrect weak ref if possible
1255 
1257  if (config.isValid())
1258  newSession = QSharedNetworkSessionManager::getSession(config);
1259 
1261  //do nothing if new and old session are the same
1262  if (networkSessionStrongRef == newSession)
1263  return;
1264  //disconnect from old session
1265  QObject::disconnect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()));
1269  }
1270 
1271  //switch to new session (null if config was invalid)
1272  networkSessionStrongRef = newSession;
1273  networkSessionWeakRef = networkSessionStrongRef.toWeakRef();
1274 
1275  if (!networkSessionStrongRef) {
1276  online = false;
1277 
1279  emit q->networkAccessibleChanged(QNetworkAccessManager::NotAccessible);
1280  else
1281  emit q->networkAccessibleChanged(QNetworkAccessManager::UnknownAccessibility);
1282 
1283  return;
1284  }
1285 
1286  //connect to new session
1287  QObject::connect(networkSessionStrongRef.data(), SIGNAL(opened()), q, SIGNAL(networkSessionConnected()), Qt::QueuedConnection);
1288  //QueuedConnection is used to avoid deleting the networkSession inside its closed signal
1289  QObject::connect(networkSessionStrongRef.data(), SIGNAL(closed()), q, SLOT(_q_networkSessionClosed()), Qt::QueuedConnection);
1290  QObject::connect(networkSessionStrongRef.data(), SIGNAL(stateChanged(QNetworkSession::State)),
1292 
1293  _q_networkSessionStateChanged(networkSessionStrongRef->state());
1294 }
QSharedPointer< T > toStrongRef() const
Promotes this weak reference to a strong one and returns a QSharedPointer object holding that referen...
#define SLOT(a)
Definition: qobjectdefs.h:226
State
This enum describes the connectivity state of the session.
QWeakPointer< QNetworkSession > networkSessionWeakRef
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
bool isValid() const
Returns true if this QNetworkConfiguration object is valid.
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
QNetworkAccessManager::NetworkAccessibility networkAccessible
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
T * data() const
Returns the value of the pointer referenced by this 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 _q_networkSessionStateChanged(QNetworkSession::State state)
static QSharedPointer< QNetworkSession > getSession(QNetworkConfiguration config)
QSharedPointer< QNetworkSession > networkSessionStrongRef

◆ fetchCachedCredentials()

QNetworkAuthenticationCredential* QNetworkAccessManagerPrivate::fetchCachedCredentials ( const QUrl url,
const QAuthenticator auth = 0 
)

◆ fetchCachedProxyCredentials()

QNetworkAuthenticationCredential* QNetworkAccessManagerPrivate::fetchCachedProxyCredentials ( const QNetworkProxy proxy,
const QAuthenticator auth = 0 
)

◆ findBackend()

QNetworkAccessBackend * QNetworkAccessManagerPrivate::findBackend ( QNetworkAccessManager::Operation  op,
const QNetworkRequest request 
)

Definition at line 94 of file qnetworkaccessbackend.cpp.

Referenced by QNetworkAccessManagerPrivate().

96 {
98  QMutexLocker locker(&factoryData()->mutex);
99  QNetworkAccessBackendFactoryData::ConstIterator it = factoryData()->constBegin(),
100  end = factoryData()->constEnd();
101  while (it != end) {
102  QNetworkAccessBackend *backend = (*it)->create(op, request);
103  if (backend) {
104  backend->manager = this;
105  return backend; // found a factory that handled our request
106  }
107  ++it;
108  }
109  }
110  return 0;
111 }
#define it(className, varName)
QNetworkAccessManagerPrivate * manager
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
static const KeyPair *const end

◆ getNetworkSession()

QSharedPointer< QNetworkSession > QNetworkAccessManagerPrivate::getNetworkSession ( ) const

Definition at line 911 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate(), and QNetworkAccessBackend::start().

912 {
916 }
QSharedPointer< T > toStrongRef() const
Promotes this weak reference to a strong one and returns a QSharedPointer object holding that referen...
QWeakPointer< QNetworkSession > networkSessionWeakRef
QSharedPointer< QNetworkSession > networkSessionStrongRef

◆ getObjectCache()

static QNetworkAccessCache* QNetworkAccessManagerPrivate::getObjectCache ( QNetworkAccessBackend backend)
inlinestatic

◆ postProcess()

QNetworkReply * QNetworkAccessManagerPrivate::postProcess ( QNetworkReply reply)

Definition at line 1105 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1106 {
1109  q->connect(reply, SIGNAL(finished()), SLOT(_q_replyFinished()));
1110 #ifndef QT_NO_OPENSSL
1111  /* In case we're compiled without SSL support, we don't have this signal and we need to
1112  * avoid getting a connection error. */
1113  q->connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(_q_replySslErrors(QList<QSslError>)));
1114 #endif
1115 #ifndef QT_NO_BEARERMANAGEMENT
1116  activeReplyCount++;
1117 #endif
1118 
1119  return reply;
1120 }
void _q_replySslErrors(const QList< QSslError > &errors)
#define SLOT(a)
Definition: qobjectdefs.h:226
#define Q_Q(Class)
Definition: qglobal.h:2483
#define SIGNAL(a)
Definition: qobjectdefs.h:227
The QNetworkAccessManager class allows the application to send network requests and receive replies...
static void setManager(QNetworkReply *reply, QNetworkAccessManager *manager)

◆ prepareMultipart()

QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart ( const QNetworkRequest request,
QHttpMultiPart multiPart 
)

Definition at line 1337 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate().

1338 {
1339  // copy the request, we probably need to add some headers
1340  QNetworkRequest newRequest(request);
1341 
1342  // add Content-Type header if not there already
1344  QByteArray contentType;
1345  contentType.reserve(34 + multiPart->d_func()->boundary.count());
1346  contentType += "multipart/";
1347  switch (multiPart->d_func()->contentType) {
1349  contentType += "related";
1350  break;
1352  contentType += "form-data";
1353  break;
1355  contentType += "alternative";
1356  break;
1357  default:
1358  contentType += "mixed";
1359  break;
1360  }
1361  // putting the boundary into quotes, recommended in RFC 2046 section 5.1.1
1362  contentType += "; boundary=\"" + multiPart->d_func()->boundary + "\"";
1363  newRequest.setHeader(QNetworkRequest::ContentTypeHeader, QVariant(contentType));
1364  }
1365 
1366  // add MIME-Version header if not there already (we must include the header
1367  // if the message conforms to RFC 2045, see section 4 of that RFC)
1368  QByteArray mimeHeader("MIME-Version");
1369  if (!request.hasRawHeader(mimeHeader))
1370  newRequest.setRawHeader(mimeHeader, QByteArray("1.0"));
1371 
1372  QIODevice *device = multiPart->d_func()->device;
1373  if (!device->isReadable()) {
1374  if (!device->isOpen()) {
1375  if (!device->open(QIODevice::ReadOnly))
1376  qWarning("could not open device for reading");
1377  } else {
1378  qWarning("device is not readable");
1379  }
1380  }
1381 
1382  return newRequest;
1383 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool hasRawHeader(const QByteArray &headerName) const
Returns true if the raw header headerName is present in this network request.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
Definition: qiodevice.cpp:544
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray boundary() const
returns the boundary.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Definition: qiodevice.cpp:530
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
Q_CORE_EXPORT void qWarning(const char *,...)
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
Definition: qiodevice.cpp:570
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66

◆ proxyAuthenticationRequired()

void QNetworkAccessManagerPrivate::proxyAuthenticationRequired ( QNetworkAccessBackend backend,
const QNetworkProxy proxy,
QAuthenticator authenticator 
)

Definition at line 1177 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessBackend::proxyAuthenticationRequired(), and QNetworkAccessManagerPrivate().

1180 {
1183  if (proxy != backend->reply->lastProxyAuthentication && (!priv || !priv->hasFailed)) {
1185  if (!cred.isNull()) {
1186  authenticator->setUser(cred.user);
1187  authenticator->setPassword(cred.password);
1188  return;
1189  }
1190  }
1191 
1192  // if we emit a signal here in synchronous mode, the user might spin
1193  // an event loop, which might recurse and lead to problems
1194  if (backend->isSynchronous())
1195  return;
1196 
1197  backend->reply->lastProxyAuthentication = proxy;
1198  emit q->proxyAuthenticationRequired(proxy, authenticator);
1199  authenticationManager->cacheProxyCredentials(proxy, authenticator);
1200 }
void setUser(const QString &user)
Sets the user used for authentication.
static QAuthenticatorPrivate * getPrivate(QAuthenticator &auth)
#define Q_Q(Class)
Definition: qglobal.h:2483
QNetworkReplyImplPrivate * reply
#define emit
Definition: qobjectdefs.h:76
The QNetworkAccessManager class allows the application to send network requests and receive replies...
QSharedPointer< QNetworkAccessAuthenticationManager > authenticationManager
static const QMetaObjectPrivate * priv(const uint *data)
void cacheProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth)
void setPassword(const QString &password)
Sets the password used for authentication.
QNetworkAuthenticationCredential fetchCachedProxyCredentials(const QNetworkProxy &proxy, const QAuthenticator *auth=0)

◆ queryProxy()

QList< QNetworkProxy > QNetworkAccessManagerPrivate::queryProxy ( const QNetworkProxyQuery query)

Definition at line 1202 of file qnetworkaccessmanager.cpp.

Referenced by QNetworkAccessManagerPrivate(), and QNetworkAccessBackend::start().

1203 {
1204  QList<QNetworkProxy> proxies;
1205  if (proxyFactory) {
1206  proxies = proxyFactory->queryProxy(query);
1207  if (proxies.isEmpty()) {
1208  qWarning("QNetworkAccessManager: factory %p has returned an empty result set",
1209  proxyFactory);
1210  proxies << QNetworkProxy::NoProxy;
1211  }
1212  } else if (proxy.type() == QNetworkProxy::DefaultProxy) {
1213  // no proxy set, query the application
1215  } else {
1216  proxies << proxy;
1217  }
1218 
1219  return proxies;
1220 }
QNetworkProxy::ProxyType type() const
Returns the proxy type for this instance.
virtual QList< QNetworkProxy > queryProxy(const QNetworkProxyQuery &query=QNetworkProxyQuery())=0
This function takes the query request, query, examines the details of the type of socket or request a...
static QList< QNetworkProxy > proxyForQuery(const QNetworkProxyQuery &query)
This function takes the query request, query, examines the details of the type of socket or request a...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
Q_CORE_EXPORT void qWarning(const char *,...)

Properties

◆ activeReplyCount

int QNetworkAccessManagerPrivate::activeReplyCount

Definition at line 145 of file qnetworkaccessmanager_p.h.

◆ authenticationManager

QSharedPointer<QNetworkAccessAuthenticationManager> QNetworkAccessManagerPrivate::authenticationManager

Definition at line 153 of file qnetworkaccessmanager_p.h.

Referenced by QNetworkAccessHttpBackend::postRequest().

◆ cookieJar

QNetworkCookieJar* QNetworkAccessManagerPrivate::cookieJar

Definition at line 129 of file qnetworkaccessmanager_p.h.

Referenced by createCookieJar().

◆ cookieJarCreated

bool QNetworkAccessManagerPrivate::cookieJarCreated

Definition at line 150 of file qnetworkaccessmanager_p.h.

Referenced by createCookieJar().

◆ httpThread

QThread* QNetworkAccessManagerPrivate::httpThread

Definition at line 131 of file qnetworkaccessmanager_p.h.

Referenced by QNetworkAccessHttpBackend::postRequest().

◆ initializeSession

bool QNetworkAccessManagerPrivate::initializeSession

Definition at line 147 of file qnetworkaccessmanager_p.h.

◆ lastSessionState

QNetworkSession::State QNetworkAccessManagerPrivate::lastSessionState

Definition at line 142 of file qnetworkaccessmanager_p.h.

◆ networkAccessible

QNetworkAccessManager::NetworkAccessibility QNetworkAccessManagerPrivate::networkAccessible

Definition at line 144 of file qnetworkaccessmanager_p.h.

◆ networkCache

QAbstractNetworkCache* QNetworkAccessManagerPrivate::networkCache

Definition at line 127 of file qnetworkaccessmanager_p.h.

Referenced by QNetworkAccessBackend::networkCache().

◆ networkConfiguration

QString QNetworkAccessManagerPrivate::networkConfiguration

Definition at line 143 of file qnetworkaccessmanager_p.h.

◆ networkSessionStrongRef

QSharedPointer<QNetworkSession> QNetworkAccessManagerPrivate::networkSessionStrongRef

Definition at line 140 of file qnetworkaccessmanager_p.h.

◆ networkSessionWeakRef

QWeakPointer<QNetworkSession> QNetworkAccessManagerPrivate::networkSessionWeakRef

Definition at line 141 of file qnetworkaccessmanager_p.h.

◆ objectCache

QNetworkAccessCache QNetworkAccessManagerPrivate::objectCache

Definition at line 157 of file qnetworkaccessmanager_p.h.

Referenced by getObjectCache().

◆ online

bool QNetworkAccessManagerPrivate::online

Definition at line 146 of file qnetworkaccessmanager_p.h.

◆ proxy

QNetworkProxy QNetworkAccessManagerPrivate::proxy

Definition at line 135 of file qnetworkaccessmanager_p.h.

Referenced by QNetworkAccessManagerPrivate().

◆ proxyFactory

QNetworkProxyFactory* QNetworkAccessManagerPrivate::proxyFactory

Definition at line 136 of file qnetworkaccessmanager_p.h.


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