Don't always send Auth headers

Use slotAuthentication again instead.
This commit is contained in:
Daniel Molkentin 2013-07-10 18:57:52 +02:00
parent 279a738aa6
commit cfaaf4a2c4
2 changed files with 3 additions and 19 deletions

View file

@ -64,6 +64,7 @@ ownCloudInfo* ownCloudInfo::instance()
ownCloudInfo::ownCloudInfo() : ownCloudInfo::ownCloudInfo() :
QObject(0), QObject(0),
_manager(0), _manager(0),
_authAttempts(0),
_lastQuotaTotalBytes(0), _lastQuotaTotalBytes(0),
_lastQuotaUsedBytes(0) _lastQuotaUsedBytes(0)
{ {
@ -88,11 +89,8 @@ void ownCloudInfo::setNetworkAccessManager( QNetworkAccessManager* qnam )
// The authenticationRequired signal is not handled because the creds are set // The authenticationRequired signal is not handled because the creds are set
// in the request header. // in the request header.
#if 0
connect( _manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)), connect( _manager, SIGNAL(authenticationRequired(QNetworkReply*, QAuthenticator*)),
this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*))); this, SLOT(slotAuthentication(QNetworkReply*,QAuthenticator*)));
#endif
// no cookie jar so far. // no cookie jar so far.
_manager->setCookieJar(new oCCookieJar); _manager->setCookieJar(new oCCookieJar);
@ -346,7 +344,6 @@ void ownCloudInfo::slotGetQuotaFinished()
#endif #endif
// FIXME: remove this later, once the new connection dialog has settled. // FIXME: remove this later, once the new connection dialog has settled.
#if 0
void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth ) void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *auth )
{ {
if( !(auth && reply) ) return; if( !(auth && reply) ) return;
@ -360,10 +357,8 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
qDebug() << "Auth request to me and I am " << this; qDebug() << "Auth request to me and I am " << this;
_authAttempts++; _authAttempts++;
MirallConfigFile cfgFile( configHandle );
qDebug() << "Authenticating request for " << reply->url(); qDebug() << "Authenticating request for " << reply->url();
if( reply->url().toString().startsWith( cfgFile.ownCloudUrl( _connection, true )) ) { if( reply->url().toString().startsWith( webdavUrl( _connection ) ) ) {
QString con = configHandle; QString con = configHandle;
if( con.isEmpty() ) con = DEFAULT_CONNECTION; if( con.isEmpty() ) con = DEFAULT_CONNECTION;
if( _credentials.contains(con)) { if( _credentials.contains(con)) {
@ -383,7 +378,6 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
reply->close(); reply->close();
} }
} }
#endif
QString ownCloudInfo::configHandle(QNetworkReply *reply) QString ownCloudInfo::configHandle(QNetworkReply *reply)
{ {
@ -616,16 +610,6 @@ void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
qDebug() << "Setting up host header: " << url.host(); qDebug() << "Setting up host header: " << url.host();
req.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString()); req.setRawHeader( QByteArray("User-Agent"), Utility::userAgentString());
QString con = _configHandle;
if( con.isEmpty() ) con = DEFAULT_CONNECTION;
if( _credentials.contains(con)) {
oCICredentials creds = _credentials.value(con);
QString concatenated = creds.user + QLatin1Char(':') + creds.passwd;
const QString b(QLatin1String("Basic "));
QByteArray data = b.toUtf8() + concatenated.toUtf8().toBase64();
req.setRawHeader( QByteArray("Authorization"), data );
}
if (size) { if (size) {
req.setHeader( QNetworkRequest::ContentLengthHeader, size); req.setHeader( QNetworkRequest::ContentLengthHeader, size);
req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml; charset=utf-8")); req.setHeader( QNetworkRequest::ContentTypeHeader, QLatin1String("text/xml; charset=utf-8"));

View file

@ -132,7 +132,7 @@ signals:
protected slots: protected slots:
void slotReplyFinished( ); void slotReplyFinished( );
void slotError( QNetworkReply::NetworkError ); void slotError( QNetworkReply::NetworkError );
// void slotAuthentication( QNetworkReply*, QAuthenticator *); void slotAuthentication( QNetworkReply*, QAuthenticator *);
#if QT46_IMPL #if QT46_IMPL
void qhttpRequestFinished(int id, bool success ); void qhttpRequestFinished(int id, bool success );