From 0a688331ec0d9d9c592e8c542946dbd66d9c6b2f Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Wed, 3 Jan 2018 12:19:25 +0900 Subject: Support request and response headers Enable specifying headers in the request and checking/using headers in the response. --- jobs/basejob.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'jobs/basejob.h') diff --git a/jobs/basejob.h b/jobs/basejob.h index e3a379fa..6b34c9f5 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -25,7 +25,6 @@ #include #include #include -#include class QNetworkReply; class QSslError; @@ -58,6 +57,7 @@ namespace QMatrixClient , ContentAccessError , NotFoundError , IncorrectRequestError + , IncorrectResponseError , UserDefinedError = 200 }; @@ -213,12 +213,21 @@ namespace QMatrixClient void failure(BaseJob*); protected: + using headers_t = QHash; + const QString& apiEndpoint() const; void setApiEndpoint(const QString& apiEndpoint); + const headers_t& requestHeaders() const; + void setRequestHeader(const headers_t::key_type& headerName, + const headers_t::mapped_type& headerValue); + void setRequestHeaders(const headers_t& headers); const QUrlQuery& query() const; void setRequestQuery(const QUrlQuery& query); const Data& requestData() const; void setRequestData(const Data& data); + const QByteArrayList& expectedContentTypes() const; + void addExpectedContentType(const QByteArray& contentType); + void setExpectedContentTypes(const QByteArrayList& contentTypes); virtual void beforeStart(const ConnectionData* connData); @@ -239,11 +248,11 @@ namespace QMatrixClient * Processes the reply. By default, parses the reply into * a QJsonDocument and calls parseJson() if it's a valid JSON. * - * @param data raw contents of a HTTP reply from the server (without headers) + * @param reply raw contents of a HTTP reply from the server (without headers) * * @see gotReply, parseJson */ - virtual Status parseReply(QByteArray data); + virtual Status parseReply(QNetworkReply* reply); /** * Processes the JSON document received from the Matrix server. @@ -264,7 +273,8 @@ namespace QMatrixClient void setLoggingCategory(LoggingCategory lcf); // Job objects should only be deleted via QObject::deleteLater - virtual ~BaseJob(); + ~BaseJob() override; + protected slots: void timeout(); -- cgit v1.2.3