diff --git a/src/gui/ocsjob.cpp b/src/gui/ocsjob.cpp index e06d7a43a..6bd55a433 100644 --- a/src/gui/ocsjob.cpp +++ b/src/gui/ocsjob.cpp @@ -29,6 +29,7 @@ OcsJob::OcsJob(AccountPtr account) { _passStatusCodes.append(OCS_SUCCESS_STATUS_CODE); _passStatusCodes.append(OCS_SUCCESS_STATUS_CODE_V2); + _passStatusCodes.append(OCS_NOT_MODIFIED_STATUS_CODE_V2); setIgnoreCredentialFailure(true); } @@ -52,6 +53,11 @@ void OcsJob::appendPath(const QString &id) setPath(path() + QLatin1Char('/') + id); } +void OcsJob::addRawHeader(const QByteArray &headerName, const QByteArray &value) +{ + _request.setRawHeader(headerName, value); +} + static QUrlQuery percentEncodeQueryItems( const QList> &items) { @@ -68,9 +74,8 @@ static QUrlQuery percentEncodeQueryItems( void OcsJob::start() { - QNetworkRequest req; - req.setRawHeader("Ocs-APIREQUEST", "true"); - req.setRawHeader("Content-Type", "application/x-www-form-urlencoded"); + addRawHeader("Ocs-APIREQUEST", "true"); + addRawHeader("Content-Type", "application/x-www-form-urlencoded"); QBuffer *buffer = new QBuffer; @@ -92,7 +97,7 @@ void OcsJob::start() } queryItems.addQueryItem(QLatin1String("format"), QLatin1String("json")); QUrl url = Utility::concatUrlPath(account()->url(), path(), queryItems); - sendRequest(_verb, url, req, buffer); + sendRequest(_verb, url, _request, buffer); AbstractNetworkJob::start(); } @@ -121,7 +126,11 @@ bool OcsJob::finished() << "has unexpected status code:" << statusCode << replyData; emit ocsError(statusCode, message); } else { - emit jobFinished(json); + // save new ETag value + if(reply()->rawHeaderList().contains("ETag")) + emit etagResponseHeaderReceived(reply()->rawHeader("ETag"), statusCode); + + emit jobFinished(json, statusCode); } return true; } diff --git a/src/gui/ocsjob.h b/src/gui/ocsjob.h index 4de4d701e..36b580a71 100644 --- a/src/gui/ocsjob.h +++ b/src/gui/ocsjob.h @@ -26,6 +26,8 @@ #define OCS_SUCCESS_STATUS_CODE 100 // Apparantly the v2.php URLs can return that #define OCS_SUCCESS_STATUS_CODE_V2 200 +// not modified when using ETag +#define OCS_NOT_MODIFIED_STATUS_CODE_V2 304 class QJsonDocument; @@ -99,6 +101,14 @@ public: */ static int getJsonReturnCode(const QJsonDocument &json, QString &message); + /** + * @brief Adds header to the request e.g. "If-None-Match" + * @param headerName a string with the header name + * @param value a string with the value + */ + void addRawHeader(const QByteArray &headerName, const QByteArray &value); + + protected slots: /** @@ -113,7 +123,7 @@ signals: * * @param reply the reply */ - void jobFinished(QJsonDocument reply); + void jobFinished(QJsonDocument reply, int statusCode); /** * The status code was not one of the expected (passing) @@ -124,6 +134,14 @@ signals: */ void ocsError(int statusCode, const QString &message); + /** + * @brief etagResponseHeaderReceived - signal to report the ETag response header value + * from ocs api v2 + * @param value - the ETag response header value + * @param statusCode - the OCS status code: 100 (!) for success + */ + void etagResponseHeaderReceived(const QByteArray &value, int statusCode); + private slots: virtual bool finished() Q_DECL_OVERRIDE; @@ -131,6 +149,7 @@ private: QByteArray _verb; QList> _params; QVector _passStatusCodes; + QNetworkRequest _request; }; } diff --git a/src/gui/ocsnavigationappsjob.cpp b/src/gui/ocsnavigationappsjob.cpp index b070873d5..db9ebf43b 100644 --- a/src/gui/ocsnavigationappsjob.cpp +++ b/src/gui/ocsnavigationappsjob.cpp @@ -30,9 +30,8 @@ void OcsNavigationAppsJob::getNavigationApps() start(); } -void OcsNavigationAppsJob::jobDone(const QJsonDocument &reply) +void OcsNavigationAppsJob::jobDone(const QJsonDocument &reply, int statusCode) { - - emit appsJobFinished(reply); + emit appsJobFinished(reply, statusCode); } } diff --git a/src/gui/ocsnavigationappsjob.h b/src/gui/ocsnavigationappsjob.h index 2c0c7bd4a..8c00c15d9 100644 --- a/src/gui/ocsnavigationappsjob.h +++ b/src/gui/ocsnavigationappsjob.h @@ -43,11 +43,12 @@ signals: * Result of the OCS request * * @param reply The reply + * @param statusCode the status code of the response */ - void appsJobFinished(const QJsonDocument &reply); + void appsJobFinished(const QJsonDocument &reply, int statusCode); private slots: - void jobDone(const QJsonDocument &reply); + void jobDone(const QJsonDocument &reply, int statusCode); }; }