Skip to content

Commit

Permalink
Propagator: Also parse OC-ETag header
Browse files Browse the repository at this point in the history
Client side part of owncloud/core#9005
  • Loading branch information
guruz committed Aug 29, 2014
1 parent 34a27c7 commit 12e2bac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
21 changes: 16 additions & 5 deletions src/mirall/propagator_legacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@

namespace Mirall {

static QByteArray get_etag_from_reply(ne_request *req)
{
QByteArray ret = parseEtag(ne_get_response_header(req, "OC-ETag"));
if (ret.isEmpty()) {
ret = parseEtag(ne_get_response_header(req, "ETag"));
}
if (ret.isEmpty()) {
ret = parseEtag(ne_get_response_header(req, "etag"));
}
return ret;
}


void PropagateUploadFileLegacy::start()
{
Expand Down Expand Up @@ -287,7 +299,8 @@ bool PropagateNeonJob::updateMTimeAndETag(const char* uri, time_t mtime)
if (updateErrorFromSession(neon_stat, req.data())) {
return false;
} else {
_item._etag = parseEtag(ne_get_response_header(req.data(), "etag"));
_item._etag = get_etag_from_reply(req.data());

QByteArray fid = parseFileId(req.data());
if( _item._fileId.isEmpty() ) {
_item._fileId = fid;
Expand Down Expand Up @@ -390,9 +403,7 @@ void PropagateDownloadFileLegacy::install_content_reader( ne_request *req, void
return;
}

QByteArray etag = parseEtag(ne_get_response_header(req, "etag"));
if(etag.isEmpty())
etag = parseEtag(ne_get_response_header(req, "ETag"));
QByteArray etag = get_etag_from_reply(req);

if (etag.isEmpty()) {
qDebug() << Q_FUNC_INFO << "No E-Tag reply by server, considering it invalid" << ne_get_response_header(req, "etag");
Expand Down Expand Up @@ -593,7 +604,7 @@ void PropagateDownloadFileLegacy::start()
}
return;
}
_item._etag = parseEtag(ne_get_response_header(req.data(), "etag"));
_item._etag = get_etag_from_reply(req.data());
break;
} while (1);

Expand Down
18 changes: 15 additions & 3 deletions src/mirall/propagator_qnam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ static qint64 chunkSize() {
return chunkSize;
}

static QByteArray get_etag_from_reply(QNetworkReply *reply)
{
QByteArray ret = parseEtag(reply->rawHeader("OC-ETag"));
if (ret.isEmpty()) {
ret = parseEtag(reply->rawHeader("ETag"));
}
return ret;
}

/**
* Fiven an error from the network, map to a SyncFileItem::Status error
*/
Expand Down Expand Up @@ -294,7 +303,8 @@ void PropagateUploadFileQNAM::slotPutFinished()
return;
}

bool finished = job->reply()->hasRawHeader("ETag");
bool finished = job->reply()->hasRawHeader("ETag")
|| job->reply()->hasRawHeader("OC-ETag");

if (!finished) {
QFileInfo fi(_propagator->_localDir + _item._file);
Expand Down Expand Up @@ -343,7 +353,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
_item._fileId = fid;
}

_item._etag = parseEtag(job->reply()->rawHeader("ETag"));
QByteArray etag = get_etag_from_reply(job->reply());
_item._etag = etag;

_item._responseTimeStamp = job->responseTimestamp();

if (job->reply()->rawHeader("X-OC-MTime") != "accepted") {
Expand Down Expand Up @@ -449,8 +461,8 @@ void GETFileJob::slotMetaDataChanged()
// We will handle the error when the job is finished.
return;
}
_etag = get_etag_from_reply(reply());

_etag = parseEtag(reply()->rawHeader("Etag"));
if (!_directDownloadUrl.isEmpty() && !_etag.isEmpty()) {
qDebug() << Q_FUNC_INFO << "Direct download used, ignoring server ETag" << _etag;
_etag = QByteArray(); // reset received ETag
Expand Down

0 comments on commit 12e2bac

Please sign in to comment.