clearifications in ownCloudInfo

This commit is contained in:
Klaas Freitag 2012-04-15 13:54:16 +02:00
parent 7c6ec3de93
commit c04315805f
2 changed files with 21 additions and 17 deletions

View file

@ -82,8 +82,8 @@ void ownCloudInfo::getRequest( const QString& path, bool webdav )
QString url = cfgFile.ownCloudUrl( _connection, webdav ) + path; QString url = cfgFile.ownCloudUrl( _connection, webdav ) + path;
QNetworkRequest request; QNetworkRequest request;
request.setUrl( QUrl( url ) ); request.setUrl( QUrl( url ) );
request.setRawHeader( "User-Agent", QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii()); setupHeaders( request, 0 );
request.setRawHeader( "Authorization", cfgFile.basicAuthHeader() );
QNetworkReply *reply = _manager->get( request ); QNetworkReply *reply = _manager->get( request );
connect( reply, SIGNAL(finished()), SLOT(slotReplyFinished())); connect( reply, SIGNAL(finished()), SLOT(slotReplyFinished()));
_directories[reply] = path; _directories[reply] = path;
@ -100,13 +100,11 @@ void ownCloudInfo::mkdirRequest( const QString& dir )
MirallConfigFile cfgFile; MirallConfigFile cfgFile;
QNetworkRequest req; QNetworkRequest req;
req.setUrl( QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ) ); req.setUrl( QUrl( cfgFile.ownCloudUrl( _connection, true ) + dir ) );
QNetworkReply *reply = davRequest("MKCOL", req, 0); QNetworkReply *reply = davRequest("MKCOL", req, 0);
connect( reply, SIGNAL(finished()), SLOT(slotMkdirFinished()) ); connect( reply, SIGNAL(finished()), SLOT(slotMkdirFinished()) );
connect( reply, SIGNAL( error(QNetworkReply::NetworkError )), connect( reply, SIGNAL( error(QNetworkReply::NetworkError )),
this, SLOT(slotError( QNetworkReply::NetworkError ))); this, SLOT(slotError(QNetworkReply::NetworkError )));
} }
void ownCloudInfo::slotMkdirFinished() void ownCloudInfo::slotMkdirFinished()
@ -239,30 +237,36 @@ void ownCloudInfo::slotError( QNetworkReply::NetworkError err)
} }
// ============================================================================ // ============================================================================
void ownCloudInfo::setupHeaders(const QString& _host, QNetworkRequest & req, quint64 size) void ownCloudInfo::setupHeaders( QNetworkRequest & req, quint64 size )
{ {
QUrl url( _host ); MirallConfigFile cfgFile;
qDebug() << "Setting up host header: " << url.host().toUtf8();
req.setRawHeader(QByteArray("Host"), url.host().toUtf8()); QUrl url( cfgFile.ownCloudUrl( QString(), false ) );
req.setRawHeader(QByteArray("Connection"), QByteArray("Keep-Alive")); qDebug() << "Setting up host header: " << url.host();
if (size) { req.setRawHeader( QByteArray("Host"), url.host().toUtf8() );
req.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(size)); req.setRawHeader( QByteArray("User-Agent"), QString("mirall-%1").arg(MIRALL_STRINGIFY(MIRALL_VERSION)).toAscii());
req.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("text/xml; charset=utf-8")); req.setRawHeader( QByteArray("Authorization"), cfgFile.basicAuthHeader() );
}
if (size) {
req.setHeader( QNetworkRequest::ContentLengthHeader, QVariant(size));
req.setHeader( QNetworkRequest::ContentTypeHeader, QVariant("text/xml; charset=utf-8"));
}
} }
QNetworkReply* ownCloudInfo::davRequest(const QString& reqVerb, QNetworkRequest& req, QByteArray *data) QNetworkReply* ownCloudInfo::davRequest(const QString& reqVerb, QNetworkRequest& req, QByteArray *data)
{ {
MirallConfigFile cfgFile; MirallConfigFile cfgFile;
setupHeaders(cfgFile.ownCloudUrl( QString(), false ), req, quint64(data ? data->size() : 0)); setupHeaders(req, quint64(data ? data->size() : 0));
if( data ) { if( data ) {
QBuffer iobuf( data ); QBuffer iobuf( data );
return _manager->sendCustomRequest(req, reqVerb.toUtf8(), &iobuf ); return _manager->sendCustomRequest(req, reqVerb.toUtf8(), &iobuf );
} else { } else {
return _manager->sendCustomRequest(req, reqVerb.toUtf8(), 0 ); return _manager->sendCustomRequest(req, reqVerb.toUtf8(), 0 );
} }
}
}
} }

View file

@ -78,7 +78,7 @@ protected slots:
void slotMkdirFinished(); void slotMkdirFinished();
private: private:
void setupHeaders(const QString&, QNetworkRequest&, quint64 ); void setupHeaders(QNetworkRequest &req, quint64 size );
QNetworkReply* davRequest(const QString&, QNetworkRequest&, QByteArray* ); QNetworkReply* davRequest(const QString&, QNetworkRequest&, QByteArray* );
static QNetworkAccessManager *_manager; static QNetworkAccessManager *_manager;